#include
using namespace std;
class student;
class date
{
public:
int dat;
date(int y=0) {dat=y;}
void display(student &stu) {cout<<stu.test<<endl;};
};
class student
{
public:
int test;
student(int x=0){test=x;}
friend void date::display(student & stu);
};
//void date::display(student &stu){cout<<stu.test<<endl;};
int main()
{
student stu1(9);
date dat(8);
dat.display(stu1);
return 0;
}
编译错误信息
[Error] invalid use of incomplete type 'class student'
[Error] forward declaration of 'class student'
为什么会编译错误?
写成文件的形式可以避免这种错误,我以前遇见过你可以试试