I have a MyClass which is a linked list for which I have overidden the operator+:
MyNode
{
int value;
MyNode* link;
}
MyClass
{
MyNode* first;
MyNode* current;
MyNode* last;
int count;
}
MyClass MyClass::operator+(MyClass* operand)
{
MyClass sum;
for(int i = 0; i < count; i++)
{
MyNode* newNode
newNode->value = value + operand->value;
sum->insert(newNode);
}
return sum;
}
When I try to implement this in my main function like so:
MyClass* a = new MyClass();
MyClass* b = new MyClass();
MyClass* c;
c = a + b;
The compiler throws an error: “cannot add two pointers”.
Are you coming from a Java background? You don’t need
newto create objects:Try this: