Hello,
i'm sure someone had the same problem before. I am trying to make one of my classes able to receive "<<"-Operations. this is my code:
// messagepipe.h
friend void operator<<
(MessagePipe
*pipe,
QString string
);
//messagepipe.cpp
void operator<<
(MessagePipe
*pipe,
QString string
) {
//do something
}
// messagepipe.h
friend void operator<<(MessagePipe *pipe, QString string);
//messagepipe.cpp
void operator<<(MessagePipe *pipe, QString string)
{
//do something
}
To copy to clipboard, switch view to plain text mode
MessagePipe is my class. This produces an error if used like this:
MessagePipe *hint;
hint << "Hi there.";
MessagePipe *hint;
hint << "Hi there.";
To copy to clipboard, switch view to plain text mode
--> error: invalid operands of types 'MessagePipe*' and 'const char [10]' to binary 'operator<<'
Hm, he isn't able to get a QString out of "Hi there". This seems to work only if used as a real parameter. Does anybody understand this behaviour? I don't want to write everytime QString("My Text"). Any ideas? Thanks.
Bookmarks