Reputation:
This structure resembles my code, I get an error: prototype for int A::getA() const does not match any in class A. My other problem is the operator<< overloading. I can not get it to work properly and I get an explicit qualification in declaration error. I tried getting the .hpp in a namespace because I saw something similar in another question posted here but this did not help. If you give me a solution me can you also provide me with details as to why my code is breaking?
//define.hpp
class A{
...
int getA() const;
int getAa() const;
};
ostream& operator<<(ostream& out, const A& obj); // defined outside of the class
//implement.cpp
ostream& define::operator<<(ostream& out, const A& obj){
return out << obj.getA()
<< obj.getAa()
<< endl;
};
int A::getA() const{ ... };
int A::getAa() const{ ... };
int main(){
return 0
}
Upvotes: 0
Views: 86
Reputation: 409356
Functions in the global scope, like your operator<<
function, does not need to be scoped. So skip the define::
part of the definition:
ostream& operator<<(...) { ... }
Upvotes: 2