0

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
}
4

1 回答 1

2

全局范围内的函数,如您的operator<<函数,不需要限定范围。所以跳过define::定义的部分:

ostream& operator<<(...) { ... }
于 2013-07-23T17:14:53.467 回答