Re: Conversion operator not being pickup by compiler
Re: Conversion operator not being pickup by compiler
- Subject: Re: Conversion operator not being pickup by compiler
- From: David Fang <email@hidden>
- Date: Fri, 13 Jan 2006 14:06:19 -0500 (EST)
> Below is a VERY contrived example of some code that's generating
> compiler warnings. We happen to turn on all warnings and treat them as
> errors, so the code HAS to be fixed. What happens is that a classes
> conversion operator is not being called (or at least the compiler can't
> figure it out) unless a static_cast is placed in front of the offending
> variable. Consider :
Hi,
I couldn't see anything immediately wrong with the code posted, so
I tried it out on the command-line (added my own hello-world-style
main()):
g++ -W -Wall -Werror -ansi -pedantic-errors foo.cc
and it happily accepted it. I also tried with various versions of g++
from 3.3 to 4.0.2, the -ansi and -pedantic-errors flags don't trigger
anything either.)
Is this the exact code triggering the problem?
How are you compiling it? What are the precise error/warnings?
> --- BEGIN ---
> #include <iostream>
>
> class Foo
> {
> public :
> explicit Foo( const char* message ) : m_str( message ) {}
>
> operator const char*() { return m_str.c_str(); }
> private :
> std::string m_str;
> };
David Fang
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden