I have a class called Device with private field ID,Type and Number. I have a bigger project but i will present only a little part here. Let's say i create an object of this class in the main and then i want to overload the > operator in order to check if the ID field of the object is bigger than a variable defined in the main called max.
i then want..
1 2 3 4 5 6
Device obj;
int max;
if (obj>max)
{
.....
}
for this overloading i used the following code
1 2 3 4 5 6 7
bool device::operator>(constint& code)
{
if (ID > code)
returntrue;
elsereturnfalse;
}
and it is working fine...
now i want to set..
max=obj;
where i mean the field ID of obj is equal to max..
can you help me?
i think is difficult because usually the object is the left-part of the = but now is the right part, so i guess there is some specific code.
You may not overload the assignment operator for fundamental types. In this case you are speaking about you have to have a conversion function. For example