CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: overloaded operator friends



>    I added a friend function to one of my classess and got a must be a 
>  member function error. the function was an overloaded = operator. 
>  when I changed it to a n overloaded << I didn't get the error. 
>  
>  friend char* operator=( char*, const HUGE&  );  // gives error
>  friend char* operator<<( char*, const HUGE&  );  //  no error here

You did not mean to use the == operator (equivalence test) rather than the =
operator (assignment) by chance?  Assignment operators usually return a
reference to the class type, so that you can copy the contents of one
instantiation into another.  The default assignment operator only gives you a
bitwise copy and will not copy the contents of any dynamically created items,
leaving you with two pointers pointing to the same content; bad news when you
delete one without deleting the other.
-- Clifton Mayo


W Komornicki's Home Page | Main Index | Thread Index