A
AngreGanon
Hi, all~ ^^
If i use #1 OK, but use # 2 error happend what's different?
#include <iostream>
/* -----------# 1------------
using std::endl;
using std::cout;
using std:stream;
*/------------------------------
//-------------# 2--------------
using namespace std; //error!!! ' x' : cannot access private member
declared in class 'Point'
class Point
{
private:
int x;
public:
Point(int _x=0):x(_x){}
friend ostream& operator<<(ostream& os, const Point& p);
};
ostream& operator<<(ostream& os, const Point& p)
{
os<<"["<<p.x<<"]"<<endl;
return os;
}
int main(void)
{
Point p;
cout << p;
return 0;
}
If i use #1 OK, but use # 2 error happend what's different?
#include <iostream>
/* -----------# 1------------
using std::endl;
using std::cout;
using std:stream;
*/------------------------------
//-------------# 2--------------
using namespace std; //error!!! ' x' : cannot access private member
declared in class 'Point'
class Point
{
private:
int x;
public:
Point(int _x=0):x(_x){}
friend ostream& operator<<(ostream& os, const Point& p);
};
ostream& operator<<(ostream& os, const Point& p)
{
os<<"["<<p.x<<"]"<<endl;
return os;
}
int main(void)
{
Point p;
cout << p;
return 0;
}