I am having an error in my compiler whenever I try to run my overloading function from my namespace inside my class, here's the function along with the error. I can provide my main file and the class/function file as well.
undefined reference to `cs_mystring::MyString::operator=(cs_mystring::MyString const&)'|
undefined reference to `cs_mystring::MyString::MyString(cs_mystring::MyString const&)'|
struct test {
int x, y, z;
test operator += (const test& other) {
this->x = this->x + other.x;
return *this;
}
};
int main() {
test x;
test y;
y.x = 77;
x.x = 9;
x.y = 8;
x.z = 7;
x += y;
std::cout << x.x << "\n"; //result 86
}
i can't be 100% certain based on what you've posted as to what exactly the issue is but my best guess is that you're attempting to dereference this add something to it but you're not specifying a specific member.
edit, sry changed it to closer match what you were trying to do
You're right dutch, it was linker errors with the copying functions. For some reason my compiler was highlighting an error inside the += function and I thought it was something generally wrong in my += overloading function.