1
class B;
class A
{
    int divident,divisor;
    friend int B::test();
public:
     A(int i,int j):divident(i),divisor(j){}
};

class B
{
public:
    int test();
};

int B::test(){}
int main(){return 1;}

It throws following error in Qt Creator with Mingwin.

enter image description here

Why is it throwing an error for forward declaration of class B? May be I am making a silly mistake, but I am not able to find it.

Sreeraj Chundayil
  • 5,548
  • 3
  • 29
  • 68

1 Answers1

1

When the compiler is parsing statement

friend int B::test();

it does not know whether class B has member function test. In this point the compiler needs the definition of class B that to determine whether this statement is correct.

Place the definition of class B before the definition of class A.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335