Sign in to follow this  

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

This topic is 3341 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
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
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

This topic is 3341 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this