struct myType{
public:
myType operator=(const myType &value){
return value;
};
};
myType einen Operator Überlastung hat für = aber wenn es in der JSON-Klasse bei it = js.allInfo.begin();
Compiler genannt wird wirft: „Keine tragfähige Überlastung für‚=‘“Keine tragfähige Überlastung für ‚=‘ Wenn es einen Operator
class JSON{
private:
vector<myType> allInfo;
public:
friend ostream &operator<<(ostream &os,const JSON &js)
{
vector<myType>::iterator it;
for(it = js.allInfo.begin(); it != js.allInfo.end();it++){
cout << "this is the info "<<(it->getNAME()) << endl;
}
return os;
};
Was sollte ich bei der Überlastung ändern = beheben dieses Problem
Normalerweise ist der Rückgabetyp für den Zuweisungsoperator ist ein Verweis auf dieser Typ wäre in diesem Fall 'myType &'. Sie geben 'myType' von' operator = 'und nicht' myType & 'zurück. Weiß nicht, ob dir das weiterhilft ... –
Ich mache das schon const myType & value, es ist dasselbe wie const myType & value, wenn es das ist, was du meinst –
Nein, 'const' ist korrekt für das Argument, aber nicht für den Rückgabetyp. –