no match for 'operator<<'

Dear c++ experts:
usually the left side of << is ostream or stringstream. but can it be user defined class?
I got compile error at place to access it since I don't know how to declare it,
should I declare it as friend?
this actually is not my ocde, it is I copied from a book(C++ cookbook)
example8-3
the article more detail describe it is in
http://gcc.gnu.org/ml/gcc-help/2011-07/msg00149.html
thanks your help a lot in advance, Eric
Yep! Here is an example:
1
2
3
4
5
6
7
8
9
class Wrapper
{
  int x;
  //etc...
public:
  //etc...

  friend ostream &operator<<(ostream &out, const Wrapper &wrapper);
};
1
2
3
4
ostream &operator<<(ostream &out, const Wrapper &wrapper)
{
  out << wrapper.x; //we have access to private data members because we are a friend of Wrapper
}
Last edited on
You certainly can have the operator << in your class. I looked at the posting, but there isn't enough info there to describe soapMsg, or other items. Can you post it?
LB , Thanks your incitation.
kooth, That book section 8.3 did not specific talk about soapMsg or other items(on its page 292, 293)
--------------------------------------------
someone in lauchpad.net reply me about this problem
--------------------------------------------
The code is incorrect.

You have not defined a streaming operator for your socket class -- the program doesn't know what you mean by "<<" with regards to Socket. Perhaps the book is asking you to extend the code -- there is no network access function calls in that example whatsoever, so the code will not actually perform any kind of HTTP request.

you need to interact with the OS, or a library that uses the OS functions -- networking is not part of C++ (but it will be for C++0x TR2 i believe, but this is in the future)
-----------------------------------------------
so stay tune(copy that 8-3.cpp and test on your better compiler than mine(g++4.5.2)
post to here , or directly email me what's develop when you have chance to test it on C++0x TR2 or better in the future.
/* g++ (or any open source camp) is prefer */
Topic archived. No new replies allowed.