G
Goran
Hi all,
I have a question regarding operator <<.
A lib of mine contains a class with an overloaded operator << as NON-
class member. This would look like:
#include <iostream>
#include <libsomelib.h>
using namespace std;
using namespace SOMELIB;
int main() {
myClass_t myObject;
cout << myObject;
return 0;
}
The example above works fine. But now I'm building a second lib with
newClass_t and myClass_t as private member:
#include <ostream>
#include <libsomelib.h>
class newClass_t {
public:
...
myClass_t GetMyClass() const;
private:
myClass_t itsMyClass;
}
&ostream operator <<(ostream&, const newClass_t&)
The source file:
...
ostream& <<(ostream& aStream, const newClass_t& aNewClass) {
aStream << aNewClass.GetMyClass();
return aStream;
}
OK, now there is a problem. It's the line "aStream <<
aNewClass.GetMyClass();". It does not compile. The error: no match for
»operator<<« in »aStream << newClass_t::GetMyClass()
So the compiler can't find the overloaded operator. Why? It's inside
libsomelib.h. What's wrong?
Thanks for answering
I have a question regarding operator <<.
A lib of mine contains a class with an overloaded operator << as NON-
class member. This would look like:
#include <iostream>
#include <libsomelib.h>
using namespace std;
using namespace SOMELIB;
int main() {
myClass_t myObject;
cout << myObject;
return 0;
}
The example above works fine. But now I'm building a second lib with
newClass_t and myClass_t as private member:
#include <ostream>
#include <libsomelib.h>
class newClass_t {
public:
...
myClass_t GetMyClass() const;
private:
myClass_t itsMyClass;
}
&ostream operator <<(ostream&, const newClass_t&)
The source file:
...
ostream& <<(ostream& aStream, const newClass_t& aNewClass) {
aStream << aNewClass.GetMyClass();
return aStream;
}
OK, now there is a problem. It's the line "aStream <<
aNewClass.GetMyClass();". It does not compile. The error: no match for
»operator<<« in »aStream << newClass_t::GetMyClass()
So the compiler can't find the overloaded operator. Why? It's inside
libsomelib.h. What's wrong?
Thanks for answering