Can you help me please with this problem? I have four classes. Honeypot header:
class Honeypot
{
public:
int getNumberOfInterfaces();
Honeypot (int numberOfInterfaces);
virtual std::string typeHoneypot()=0;
protected:
int numberOfInterfaces;
};
Honeypot.cpp:
Honeypot::Honeypot(int numberOfInterfaces){
this-> numberOfInterfaces = numberOfInterfaces;
}
int Honeypot::getNumberOfInterfaces(){
return numberOfInterfaces;
}
Class Honeypot has child HoneypotV and HoneypotN. Now I created object with number of 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;
}
In the main function:
NetworkType select;
Honeypot *p;
p = select.createObject(1,1,1);
cout << p->typeHoneypot() << endl;
cout << p-> getNumberOfInterfaces() << endl;
typeHoneypot() is correct, but getNumberOfInterfaces() returned value -858993460, correct is 3.
Thank you for reply.