You can't declare an object of a class until you define it. Forward declaration only allows you to address that you'll have definitions for it later. Until it's defined you can only use the name of the class.
Code:
// This is legal
#include <iostream>
class CLASS2;
class CLASS1 {
public:
void myMethod1(CLASS2);
};
class CLASS2 {
public:
void myMethod2() { std::cout << "Inside myMethod2"; }
};
void CLASS1::myMethod1(CLASS2 c2Obj) { c2Obj.myMethod2(); }
Code:
// This is illegal
#include <iostream>
class CLASS2;
class CLASS1 {
public:
void myMethod1(CLASS2 c2Obj) { // c2Obj is an incomplete type
c2Obj.myMethod2();
}
};
class CLASS2 {
public:
void myMethod2() { std::cout << "Inside myMethod2"; }
};