The program consists of 5 files: "a.cpp", "ah", "b.cpp", "bh", "main.cpp".
Halyards with h extensions contain class declarations. In files with the cpp extension, the implementation of class methods.
The build is as follows: g ++ main.cpp a.cpp b.cpp
The contents of the file "ah"
class A { public: void anyfunc(); };
Contents of the file "a.cpp"
void A::anyfunc() { func(); }
File Contents "bh"
#include "ah" class B { public: void func(); private: A obj; };
Contents of the file "b.cpp"
void B::func() { // ... }
It is necessary that the member functions of class A have access to the function members of class B. But, with this code, the compiler will of course generate an error. Both classes must have access to func (), parent B and A. At the same time, class A must be declared before class B in order to be able to declare A obj in class B. I think the problem would be resolved by class A is from B (class A: public B), but for the above reasons, this is not possible.
Bis possible only through an object of classBWhat classBobject were you going to access the functions of classB? Why do you call classB"parent"? I do not see any inheritance in your code. - AnT pmbhin thea.cppimplementation file, no? Show how you want to access functionsB- hopefully not through a member ofB objin classA? :) - Harry