• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Conversion operator not being pickup by compiler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Conversion operator not being pickup by compiler (From: "Greg Norz" <email@hidden>)

  • Prev by Date: Conversion operator not being picked up by compiler
  • Next by Date: Re: Project doesn't link to correct subproject
  • Previous by thread: Conversion operator not being pickup by compiler
  • Next by thread: RE: Conversion operator not being pickup by compiler
  • Index(es):
    • Date
    • Thread