#include<iostream>
usingnamespace std;
class test;
class sampletest
{
public:
void getainb(test & x);
};
void sampletest::getainb(test & x)
{
cout<<"In sampletest:getainb="<<x.a<<endl;
}
class test
{
int a;
public:
int geta() {return a;}
void seta(int x) { a = x;}
friendvoid sampletest::getainb(test & x);
};
main()
{
test t;
t.seta(23);
sampletest s;
s.getainb(t);
}
giving error:
class.cpp: In method `void sampletest::getainb(test &)':
class.cpp:14: invalid use of undefined type `class test'
class.cpp:6: forward declaration of `class test'
But if i move defination of getainb after class test
it works fine.