S
shuisheng
Dear All,
I have a question on operator << overloading on a class in a
namespace. For example:
#include <iostream>
namespace Geometry
{
class Point
{
friend std:stream& operator << (std:stream& out, const Point&
pt);
private:
double x, y, z;
};
};
inline std:stream& operator << (std:stream& out, const Point& pt)
{
out << pt.x << pt.y << pt.z;
return out
}
I got compilation errors: can not access class Point 's private
members x, y, and z. If I move the overloading function into the
Geometry namespace, it is fine. But I want to keep the function
global and do not want to make x, y, z public, how can I do for it?
Thank you for your kind help in advance!
Shuisheng
I have a question on operator << overloading on a class in a
namespace. For example:
#include <iostream>
namespace Geometry
{
class Point
{
friend std:stream& operator << (std:stream& out, const Point&
pt);
private:
double x, y, z;
};
};
inline std:stream& operator << (std:stream& out, const Point& pt)
{
out << pt.x << pt.y << pt.z;
return out
}
I got compilation errors: can not access class Point 's private
members x, y, and z. If I move the overloading function into the
Geometry namespace, it is fine. But I want to keep the function
global and do not want to make x, y, z public, how can I do for it?
Thank you for your kind help in advance!
Shuisheng