• 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 picked up by compiler
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Conversion operator not being picked up by compiler


  • Subject: Re: Conversion operator not being picked up by compiler
  • From: David Fang <email@hidden>
  • Date: Fri, 13 Jan 2006 14:46:42 -0500 (EST)

Sorry to reply to myself...
Another suggestion embedded below:

> --- 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;
> };
>
> void Write( const char* msg, ... )
> {
>     std::cout << msg << std::endl;
> }

// this will cause the compiler to look for a conversion to const char*
// when passing something else as the 2nd argument.
void Write(const char* msg, const char* str) {
	// stuff goes here
}

> int main( int argc, char* const argv[] )
> {
>     Foo foo( "Hello, World!" );
>     Write( "%s", foo );
>     return 0;
> }
> --- END ---

BTW, your code looks like it's going to print

%s

because none of the variadic arguments are actually used.
I'm sure you know what you meant.


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 picked up by compiler (From: "Greg Norz" <email@hidden>)

  • Prev by Date: Re: Conversion operator not being picked up by compiler
  • Next by Date: Re: MacIntel apps behaves weirdly when compiled with -02 not -01 - Almost solved(auto-vectorization issue)
  • Previous by thread: Re: Conversion operator not being picked up by compiler
  • Next by thread: RE: Conversion operator not being picked up by compiler
  • Index(es):
    • Date
    • Thread