I have a header file which contains a class with an assignment operator. Now I want to define my function inside my .cpp file.
My header file contains: Car &operator=(const Car &other);
Now in my cpp file I would like to do something like: Car::Car &operator=(const Car &other)
{
}
Unfortunately this doesn’t seem to be the right syntax. So how can I define my assignment operator when I have the function declaration and the function definition separated?
You’re almost there; you need to qualify the function name to indicate that it’s a member: