友员!帮帮忙啊!
//: test.h
#ifndef TEST_H_
#define TEST_H_
class user;
class uti
{
int _data;
uti* _next;
public:
friend class user;
uti();
};
class user
{
user* use;
public:
user();
void access();
};
#endif // TEST_H_
// test.cpp
#include "test.h"
#include <cstdlib>
uti::uti()
{
_data=0;//问题在这里,具体见下面
_next=NULL;//问题在这里,具体见下面
}
user::user()
{
use=NULL;
}
void user::access()
{
_data=1;
_next=NULL;
}
// test_test.cpp
#include "test.h"
void main()
{
user u1;
}
程序就这么简单,但是老是编译不通过。出现的错误:
error C2065: '_data' : undeclared identifier
error C2065: '_next' : undeclared identifier
情急之下找来了钱能的《c++程序设计教程》书上说,整个类可以是另一个类的友员叫友类。一个类的私有和保护的数据成员可以被其友类使用。不知道是我的语法有问题,还是我的编译器(VC++6)有问题,我就按照书上的原则做的,怎么会老师编译不通过呢?
请各位指点一二,谢谢先!