Anything wrong with this overloading
TankStatus is enum type....Code:TankStatus operator=(int number, TankStatus ts)
{
return ts = number;
}
//: error C2801: 'operator =' must be a non-static member
Printable View
Anything wrong with this overloading
TankStatus is enum type....Code:TankStatus operator=(int number, TankStatus ts)
{
return ts = number;
}
//: error C2801: 'operator =' must be a non-static member
You can only overload operators on classes, structs and unions. MSDN explains that if you look up the error number. Why would you want to overload the = operator on an enum anyway?
because...Quote:
Originally Posted by GCDEF
again, ts is enum.... // enum TankStatus {unknown, empty, half, full};Code:if ( (ts>3 ) || (ts<0) ) {
ts=0 ;
}
// : error C2440: '=' : cannot convert from 'int' to TankStatus'
The point of an enum is to provide names for its possible values. You should use those names when assigning it a value, otherwise there's no point in using an enum.
Code:enum TankStatus
{
unknown,
empty,
full
}:
TanksStatus ts;
ts = unknown;
hey you right, thanx :)Quote:
Originally Posted by GCDEF
elements of an enum can only be assigned values at the point of declaration.
If you define a variable that happens to be an enum (and it is not a const) you can assign to it as much as you want.Quote:
Originally Posted by s_kannan55
Am I misunderstanding your point?Code:enum colors
{
RED,
BLUE,
GREEN
}
colors textColor (RED);
// later I can do this
textColor = BLUE;