Class are have written my classes in different files. Such as:
-main.cpp
-ClassA.cpp
-ClassB.cpp
-ClassC.cpp
main.cpp has the #include for all classes, but I also need to access Object instantiated from ClassA in main inside ClassB and ClassC.
main.cpp
#include "ClassA.cpp"
#include "ClassB.cpp"
#include "ClassC.cpp"
ClassA objA;
ClassB objB(objA);
ClassB objC(objA);
. .
classB.cpp
#include "ClassB.cpp" //How to avoid the double declaration and yet make the class recognizable?
class ClassB{
public:
ClassA objA;
ClassB(ClassA obj){
this->objA = obj; // Is it the right way in C++?
}
};
I know it is not right. But why not? In Java makes sense.