V
V
Vadim Ushakov2021-08-02 16:09:19
C++ / C#
Vadim Ushakov, 2021-08-02 16:09:19

Class is not defined in child file after include, why?

There are two files,

LicenseKey.h

#include "LicensesProduct.h"

namespace Machinarium {
  namespace Licenses_System {

    #warning "LICENSE_KEY Class creation"
    class LicenseKey : IValidationInterface {

...


LicensesProduct.h
#include "LicenseKey.hpp"
#include "IValidationInterface.h"

namespace Machinarium {
  namespace Licenses_System {

    class LicensesProduct : public IValidationInterface, Machinarium::BaseClasses::Nameable {

    private:
      Cryptographic::CryptographicKeyPair cryptographicKeyPair;
      LicenseKey activeLicense;
...


==== Building licenses (release) ====
LicenseKey.cpp
In file included from src/LicenseKey.cpp:1:
src/LicenseKey.hpp:11:4: warning: #warning "LICENSE_KEY Class creation" [-Wcpp]
   11 |   #warning "LICENSE_KEY Class creation"
      |    ^~~~~~~
In file included from src/LicenseKey.hpp:6,
                 from src/LicenseKey.cpp:1:
src/LicensesProduct.h:17:4: error: ‘LicenseKey’ does not name a type
   17 |    LicenseKey activeLicense;


For what reason is it so? In essence, the LicenseKey class is defined when included in the LicenseKey.h file

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-08-02
@Nightmare1

Firstly, for some reason you have the extension h somewhere, and somewhere hpp. It needs to be brought to one.
Secondly, you have a cyclic include, this will not work. This must be decided. For example, you can solve with forward declaration and pimpl.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question