[讨论]实在不解与~
#include<iostream>
using namespace std;
class A{
public:
friend ostream& operator<< (ostream&,const A&);
A():i(0),j(0),c('a'){}
private:
const int i;
const int j;
char c;
};
int main()
{
A a;
cout<<&a<<endl;
cout<<a;
return 0;
}
ostream& operator<< (ostream& out,const A& i_)
{
return out<<&i_.i<<" "<<&i_.j<<" ";
}
当把<iostream>改为<iostream.h>并删掉using namespace std;编译器就不报错了,通过~~不然报错不能访问私有成员~重载的不是友元函数么,都不能访问!实在想不出什么原因!请大虾指点~
using namespace std;
class A{
public:
friend ostream& operator<< (ostream&,const A&);
A():i(0),j(0),c('a'){}
private:
const int i;
const int j;
char c;
};
int main()
{
A a;
cout<<&a<<endl;
cout<<a;
return 0;
}
ostream& operator<< (ostream& out,const A& i_)
{
return out<<&i_.i<<" "<<&i_.j<<" ";
}