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

## Recommended Posts

I'm building a fixed-point class as an exercise, and I've hit a small problem when overloading the equals operator. I need to overload it so that I can convert from the fixed point representation to a floating point representation. Theoretically I think that the function should be declared thus,

namespace FixedPointMath {

class Fixed
{
...
friend float& operator=(float& leftHand, const Fixed& rightHand);
...
};

float& operator=(float& leftHand, const Fixed& rightHand)
{
...
}

}


But Visual C++ complains when compiling:
error C2801: 'operator =' must be a <Unknown> member

MSDN states that the = operator must be a member of the left-hand class, but how is this possible when using a predefined type? Thanks, Adam

##### Share on other sites
You can't provide an assignment operator like that. However you could provide an implicit conversion operator, but be wary of such constructs.

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 9
• 13
• 81
• 11
• 10
• ### Forum Statistics

• Total Topics
632969
• Total Posts
3009594
• ### Who's Online (See full list)

There are no registered users currently online

×