Ambiguos overload for operator << ?


I have :

stringstream<<"hello";

long pos= stringstream.tellp();
W_debug()<<pos;

It works, but:

W_debug()<<stringstream.tellp();
gives me the next error when build:

ambiguous overload for 'operator<<' in 'W_debug() << strio.std::strstream::<anonymous>.std::basic_iostream<char, std::char_traits<char> >::<anonymous>.std::basic_ostream<_CharT, _Traits>::tellp [with _CharT = char, _Traits = std::char_traits<char>]()'

I have :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
W_debug& operator << (QString data);
  W_debug& operator << (std::string  data);
  W_debug& operator << (const char data);
  W_debug& operator << (const char * data);

  W_debug& operator << (bool   data);
  W_debug& operator << (long   data);

  W_debug& operator << (int   data);
  W_debug& operator << (double  data);
  W_debug& operator << (float  data);

  and the code for every W_debug is 
  os<<data;
 (being 'os' a stringstream object)



Any idea ?
Thanks
Last edited on
The result of tellp() is unsigned (something, just look what the result ist) and you don't provide the requested operator
Ok ! Thanks
tellp returns std::streampos: http://www.cplusplus.com/reference/iostream/ostream/tellp/
If you have many overloads you can easily get ambiguity for the types you didn't overload but which are compatible with the ones you used in the overloaded parameters.
Some solutions could be:
- Overload for any built-in type and any other type you know will be needed
- Overload only for few types so that the ambiguity won't be a problem ( only one possible implicit cast given a type )
- Use some sort of template instead of he overloads ( This if the code is the same for many overloads )
Topic archived. No new replies allowed.