I am attempting to declare an operator override (ClassName& operator=(const ClassName& rhs)
) within the header file and then define it in the .cpp, but I am running into many different errors.
My original setup:
ClassName.h:
#ifndef CLASSNAME_H
#define CLASSNAME_H
class ClassName {
private:
ClassName& operator=(const ClassName& rhs);
};
#endif CLASSNAME_H
ClassName.cpp:
#include "ClassName.h"
ClassName& operator=(const ClassName& rhs) {
// some logic
}
The .cpp file errors, saying operator= must be a member function
. I then tried:
ClassName.h:
#ifndef CLASSNAME_H
#define CLASSNAME_H
class ClassName {
private:
ClassName& operator=(const ClassName& rhs);
};
#endif CLASSNAME_H
ClassName.cpp:
#include "ClassName.h"
ClassName& ClassName::operator=(const ClassName& rhs) {
// some logic
}
but the .cpp file now says qualified name is not allowed
.
I additionally tried the solution outlined here, but the error operator= must be a member function
now shows up on both declarations in the .h as well as in the .cpp.