L
Larry Lindsey
Aieeeeaiiieeaiiieii, ah think ah need some pro-zac
For some reason, my object variables aren't keeping their values outside of
the method scope. For instance, given:
//Begin code
class Parent{
public:
Parent(){}
virtual ~Parent(){}
virtual void setSomething(int thing){}
virtual int getSomething(){return 0}
...
};
class Child: public Parent{
public:
Child(){...}
Child(int thing){
...
setSomething(thing);
}
~Child(){...}
void setSomething(int thing){
something=thing;
}
int getSomething(){
return something;
}
private:
int something;
};
int main(){
Child *c;
c = new Child(12);
cout << c.getSomething()<<endl;
return 0;
}
//end code
the output will not be 12, but -842150451. I suspect that I'm doing
something wrong with the virtual keyword. Can anyone explain this?
Thanks,
Larry
For some reason, my object variables aren't keeping their values outside of
the method scope. For instance, given:
//Begin code
class Parent{
public:
Parent(){}
virtual ~Parent(){}
virtual void setSomething(int thing){}
virtual int getSomething(){return 0}
...
};
class Child: public Parent{
public:
Child(){...}
Child(int thing){
...
setSomething(thing);
}
~Child(){...}
void setSomething(int thing){
something=thing;
}
int getSomething(){
return something;
}
private:
int something;
};
int main(){
Child *c;
c = new Child(12);
cout << c.getSomething()<<endl;
return 0;
}
//end code
the output will not be 12, but -842150451. I suspect that I'm doing
something wrong with the virtual keyword. Can anyone explain this?
Thanks,
Larry