View Single Post

  #2 (permalink)  
Old 10-17-2006, 12:10 AM
Q.E.D. Q.E.D. is offline
Junior Member
 
Join Date: Oct 2006
Location: Hudson Valley, NY
Posts: 2
Rep Power: 0
Q.E.D.
Default

Don't know if you still need help with this, but... I just joined the forum and it seems like a ghost town.

The problem is with your code and not gcc. Your operator= method requires the argument to be a modifiable reference to a testClass (also sometimes called an l-value meaning it is allowed to appear on the left-hand side of an assignment). The return type of your operator* method is an r-value (meaning it is only allowed to appear on the right-hand side of an assignment).

It is good to become familiar with the proper signature and return-type of assignment statements. When dealing with objects, an assignment should declare its formal parameter to be a *constant* reference to an object (this allows the compiler to allow temporaries or other r-values as argument. Also, an assignment typically returns a (modifiable) reference to an object, rather than a object value. This allows us to write statements like
Code:
x = y = 2;
So, to summarize, the declaration of your assignment operator should look like
Code:
      testClass& operator= (testClass const& input)
         {
            a = input.a;
            return *this;
         }
If you are not familiar with the special pointer 'this', then I recommend that you look it up.

Hope this helps.

-Matthew-
Reply With Quote