この問題を教えてください。私は4つのクラスを持っています。ハニーポット ヘッダー:
class Honeypot
{
public:
int getNumberOfInterfaces();
Honeypot (int numberOfInterfaces);
virtual std::string typeHoneypot()=0;
protected:
int numberOfInterfaces;
};
ハニーポット.cpp:
Honeypot::Honeypot(int numberOfInterfaces){
this-> numberOfInterfaces = numberOfInterfaces;
}
int Honeypot::getNumberOfInterfaces(){
return numberOfInterfaces;
}
クラス Honeypot には、子 HoneypotV と HoneypotN があります。今私はneteorkInterfacesの数でオブジェクトを作成しました:
Honeypot* NetworkType::createObject(int res1, int res2, int res3) {
if (res1 == 1 && res2 == 1 && res3 == 1) {
HoneypotV p1(3);
return &p1;
} else {
HoneypotN p2(3);
return &p2;
}
メイン関数では:
NetworkType select;
Honeypot *p;
p = select.createObject(1,1,1);
cout << p->typeHoneypot() << endl;
cout << p-> getNumberOfInterfaces() << endl;
typeHoneypot() は正しいですが、getNumberOfInterfaces() は値 -858993460 を返しました。正しい値は 3 です。
返信ありがとうございます。