?
=?ISO-8859-1?Q?=22J=2EJ=2EGarc=EDa=22?=
Hi,
I have defined an static operator in a class, and when I try to use it
inside of the class, my compiler --Visual C++ 7.1-- complains saying
that there not exist an operator that suits the statement.
I have something like this:
namespace rend {
class Loader {
public:
void aFunction(void);
...
protected:
class Object;
...
private:
static ostream &operator<<(ostream &os,
const Object &object);
...
};
void Loader::aFunction(void) {
Object object;
...
cout << object; // Complains about not being a overloaded op.
// that permits the object class in the right
// of the binary operator "<<"
operator<<(cout, object); // This works ok, and it's really the
// same thing
}
} // namespace rend
I need the class Object to be defined as private, as it's really needed
outside of the Loader class. For this reason I cannot define the
operator<< in the rend namespace scope, as in this scope Loader::Object
is not accessible. So I need it to be a private static member of the
class. But then there seem to be scope exceptions for static operators
in a class, as I cannot use "cout << object", when it should be legal.
Can someone give me some light about this?
Thanks,
J.J.
I have defined an static operator in a class, and when I try to use it
inside of the class, my compiler --Visual C++ 7.1-- complains saying
that there not exist an operator that suits the statement.
I have something like this:
namespace rend {
class Loader {
public:
void aFunction(void);
...
protected:
class Object;
...
private:
static ostream &operator<<(ostream &os,
const Object &object);
...
};
void Loader::aFunction(void) {
Object object;
...
cout << object; // Complains about not being a overloaded op.
// that permits the object class in the right
// of the binary operator "<<"
operator<<(cout, object); // This works ok, and it's really the
// same thing
}
} // namespace rend
I need the class Object to be defined as private, as it's really needed
outside of the Loader class. For this reason I cannot define the
operator<< in the rend namespace scope, as in this scope Loader::Object
is not accessible. So I need it to be a private static member of the
class. But then there seem to be scope exceptions for static operators
in a class, as I cannot use "cout << object", when it should be legal.
Can someone give me some light about this?
Thanks,
J.J.