I have overloaded + operator conditionally. When I use the overloaded op in main separately , it works as demanded. But I need to have it called within the add function and it throws me this error. Please help me resolve this!!
>Solution :
The problem is that add is a non-static member function and not a free function. So you must call it using a Time object.
You can solve this either by making add a free function as shown below or calling it on a Time object like t3.add(t1, t2).
class Time
{
//your code here
};
//make add a free function
Time add(const Time&a, const Time&b)
//-------^^^^^---------^^^^^----------->added const here
{
return a+b;
}
