Example:
long a;
BoundedCounter e;
So I want to assign the value of the private variable counter in the class to a.
a=e;
Tried using this:
long int & operator=(long b)
{
b=counter;
return b;
}
and
long int & operator=(long b, BoundedCounter &a)
{
b=a.getCounter();
return b;
}
Which return a compile error:
cannot convert
BoundedCounter' tolong int’ in assignment
and
`long int& operator=(long int, BoundedCounter&)’ must be a nonstatic member function
How do I define an operator= outside of the class which will work when the left side is a normal variable and not an object?
operator=is unsuitable here as the left-hand side of the assignment is a primitive type (and you cannot defineoperator=for primitive types). Try givingBoundedCounteranoperator long, e.g.: