超简单的c++运行不了

来源:百度知道 编辑:UC知道 时间:2024/06/02 08:11:17
#include "iostream.h"
class b;
class a
{
int x;
public:
void dd(b & c)
{

cout<<c.y;
}
};
class b
{
int y;

friend void a::dd(b &);
};
void main()
{

}
怎么运行不了呢?
提示说:use of undefined type 'b'
left of '.y' must have class/struct/union type
这两句什么意思啊 请指点啊

#include "iostream"
using namespace std;
class b;
class a
{
int x;
public:
void dd(b & ) ;

};
class b
{
int y;
friend void a::dd(b &);
};
void a::dd(b &c)
{

cout<<c.y;
}
void main()
{

}

试下class b写在class a上面,直接class b;这种用法还是第一次看到,不过估计dd又不行了,定义写在头文件里面试下吧

因为编译器看到
void dd(b & c)
{
cout<<c.y;
}
时并没有发现b类有成员y

class里面只做函数dd的声明,内容单独写