Jump to content
  • Advertisement
Sign in to follow this  
Daggerbot

non-user-defined-type operator overloads with gcc/c++?

This topic is 3555 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a compiler option or anything alike that enables static operator overloads with gcc/c++? I'm trying to implement something along these lines:
static TempString
operator+ ( const wchar_t* a, const wchar_t* b )
{
  return TempString( a ) + b;
}


[Edited by - Daggerbot on October 24, 2008 9:11:32 PM]

Share this post


Link to post
Share on other sites
Advertisement
You can create non-member operator overloads; however, at least one of the arguments must be of a user defined type (or pointer/reference to a user defined type).

Share this post


Link to post
Share on other sites
Ah thanks anyway. Are assignment operators called from right to left or left to right? For example, would this work?


String makeSomeLameString()
{
return String("some ") += "lame " += "string" += ".\n";
}

Share this post


Link to post
Share on other sites
Overloaded operators follow the same precedence and associativity rules that a non-overloaded version would. So no, that wouldn't work.

Share this post


Link to post
Share on other sites
However, there's no reason that you couldn't rewrite that function to use + instead of +=.

String makeSomeLameString()
{
return String("some ") + "lame " + "string" + ".\n";
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!