This question has already been answered:
- Inclusion of C ++ files. 1 reply
There is a BaseClass :
// BaseClass.h #pragma once #include "ChildClass.h" class BaseClass { public: BaseClass(); ~BaseClass(); ChildClass obj; }; // BaseClass.cpp #include "BaseClass.h" BaseClass::BaseClass() { } BaseClass::~BaseClass() { } There is a ChildClass :
// ChildClass.h #pragma once #include "BaseClass.h" class ChildClass { public: ChildClass(BaseClass &obj); ~ChildClass(); BaseClass obj; }; // ChildClass.cpp #include "ChildClass.h" ChildClass::ChildClass(BaseClass &obj) { this->obj = obj; } ChildClass::~ChildClass() { } Description: The reference to the BaseClass object is passed to the BaseClass and the internal object of the base class is initialized, which is located in the child class. In the base class, a field is declared, which must refer to the subsequently initialized object of the child class. Those. roughly speaking, it is necessary that the child class has access to its object through the base class.
The question is: did this architecture work quite well in .NET-е , what do not like the pluses and how can I get around the problem? In the pros - this example is not compiled, VS gives a variety of errors, error numbers: C2061 , C2146 , C4430 .
ps as far as I understood, given my poor knowledge of the pros, there exists some kind of recursive dependency of the header files and it is not quite clear why the preprocessor # pragma #pragma once does not work.
The pps solution in this reply is from comments: Include C ++ files. - a crutch (and with strong limitations), is there any normal solution?