我的电脑装vs2008总是报错,不得已装了个VC6 sp6暂时先用用,发现使用重载输入输出运算符时有问题
demo3.h:
复制代码
#include <iostream.h>
class demo3
{
public:
demo3();
virtual ~demo3();
friend ostream& operator << (ostream& out,const demo3& d);
friend istream& operator >> (istream& in,demo3& d);
private:
int x;
};
复制代码
复制代码
#include "stdafx.h"
#include "demo3.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
demo3::demo3()
{
}
demo3::~demo3()
{
}
ostream& operator << (ostream& out,const demo3& d)
{
out<<d.x<<endl;
return out;
}
istream& operator >> (istream& in,demo3& d)
{
return in;
}
复制代码
编译后报错:
error C2248: 'x' : cannot access private member declared in class 'demo3'
查了下网上的资料,说是vc6的bug,而在vc8中就没问题,暂时的解决办法是将#include<iostream>改为#include<iostream.h>
本文转自Phinecos(洞庭散人)博客园博客,原文链接:http://www.cnblogs.com/phinecos/archive/2008/07/21/1247904.html,如需转载请自行联系原作者