class B; <<<<Forward reference
class A
{
void get();
};
void A::get()
{
B b_class; <<<<< Error
b_class.test();
}
class B
{
void test();
};
void B::test()
{
cout << "test" << endl;
}
I made a couple of marks in your code above. First, a class reference is an instruction to the compiler that a class exists even though the compiler has not yet seen the class declaration. Here it says B is a class.
So far, so good.
However in A::get(), there is an object b_class with a type of B. For the compiler to accept this, there must be a class B (there is according to the forward reference) and that class B must have a default constructor (which you can't tell from the forward reference). So you get a compile error.
You say you get a linker error. I doubt that. It's a compile error.
The forward reference is good enough for the compiler to allow a B* but not good enough for the compiler to allow a B object. When you need a B object, then you have to put the class B declaration before the class A declaration.