Sign in to follow this  
Daggerbot

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

Recommended Posts

Daggerbot    127
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
SiCrane    11839
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
Daggerbot    127
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
SiCrane    11839
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

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