用之前要让编译器知道这个东西是什么
但是要注意
你只告诉了这是什么
所以以后不能用还没定义的类的成员和函数
嵌入式 ARM 单片机 驱动 RT操作系统 J2ME LINUX Symbian C C++ 数据结构 JAVA Oracle 设计模式 软件工程 JSP
用之前要让编译器知道这个东西是什么
但是要注意
你只告诉了这是什么
所以以后不能用还没定义的类的成员和函数
#include<iostream>
using namespace std;
class A
{
public:
void Display(){cout<<x<<endl;}
int GetX(){return x;}
void Set(int i);
friend class B;
private:
int x;
};
class B
{
public:
int Set(int i);
private:
A a;
};
int B::Set(int i)
{
a.x=i;
return (a.x);
}
void main()
{
B b;
A c;
b.Set(2);
c.Display();
}
不过你这样做无意义;