Here's an example of the error. If you try to compile this with the latest version of gcc it will fail. For some reason gcc seems unable to pass the returned testCase type from Q * x, the operator* function, to the operator= function. Is there a way to get it to do this? The error was brought up in a much larger program I'm working on where an object's function returns an object of the same type, and then assigns it to a different object with operator=. I've tried converting the operator* function to a friend function instead of a member function, but that gives exactly the same errors.
Code:
#include<iostream>
using namespace std;
class testClass
{
private:
int a;
public:
testClass(testClass& input) { a = input.a; }
testClass(int x) { a = x; }
testClass() { a = 1; }
testClass operator=(testClass& input)
{ a = input.a; }
testClass operator*(int x)
{ testClass temp(a * x); return temp; }
};
int main()
{
int x = 3;
int y = 4;
testClass R(y);
testClass Q;
R = Q * x;
return 0;
}