Re: error C2440: 'type cast' : cannot convert from 'std::stringstream' to 'void *'
- From: mathieu.malaterre@xxxxxxxxx
- Date: 18 Aug 2006 15:52:00 -0700
Igor Tandetnik wrote:
mathieu.malaterre@xxxxxxxxx wrote:
I don't understand why I cannot do the following with vs7:
-----------------------------------
std::stringstream ss;
if ( (void*)ss == 0) {
std::cerr << "zero\n";
}
The compiler is returning:
ss.cxx(7) : error C2440: 'type cast' : cannot convert from
'std::stringstream' to 'void *'
Ambiguous user-defined-conversion
But stringstream should inherit this from its parent ios, right ?
Looks like a bug in how virtual base class is handled. It works with
istringstream and ostringstream, but not for stringstream. The
difference is stringstream is derived from ios twice, via istream and
ostream, as a virtual base class. It appears the compiler does not
realize that and fails because it doesn't know which copy of the base
class to call operator void*() on.
The bug appears to affect only implicitly invoked conversion operators.
The following work:
if (!ss) {...}
if (ss.operator void*() == 0) {...}
I don't have VC8 handy at the moment to check there.
Thanks Igor, both workarounds work for me.
Mathieu
.
- References:
- error C2440: 'type cast' : cannot convert from 'std::stringstream' to 'void *'
- From: mathieu . malaterre
- Re: error C2440: 'type cast' : cannot convert from 'std::stringstream' to 'void *'
- From: Igor Tandetnik
- error C2440: 'type cast' : cannot convert from 'std::stringstream' to 'void *'
- Prev by Date: Re: error C2440: 'type cast' : cannot convert from 'std::stringstream' to 'void *'
- Next by Date: Re: STL Slow - VS2005
- Previous by thread: Re: error C2440: 'type cast' : cannot convert from 'std::stringstream' to 'void *'
- Index(es):
Relevant Pages
|