Why it is saying incomplete type, why can't I use friend function like this?
#include<iostream>
using namespace std;
class test;
class test2{
public:
void outd(test t)
{
cout <<t.x<<endl;
cout<<t.y<<endl;
}
};
class test{
int x;
int y;
friend void test2::outd(test t);
public:
test(int x,int y)
{
this->x=x;
this->y=y;
}
};
int main()
{
test t(1,2);
test2 z;
z.outd(t);
}
error: prog.cpp: In member function 'void test2::outd(test)':
prog.cpp:6:20: error: 't' has incomplete type
void outd(test t)
prog.cpp:3:7: note: forward declaration of 'class test'
class test;