I have a parent class and two child classes that inherit from the parent class. The parent class has a protected pointer to something, and a method to access that pointer.
class parent{
public:
int* accessPtr(){
return ptr;
}
protected:
int* ptr;
};
class child1 : public parent{
public:
child1(int* somevalue){
//initializes ptr to somevalue, a pointer to something stored elsewhere
}
};
class child2 : public parent{
public:
child2(){
//initializes ptr using new
}
~child2(){
delete ptr;
}
};
int main(){
child2* instance = new child2();
instance->accessPtr(); //this line is where my debugger stops
}
Naturally, my code compiles, and it even runs when I don't call accessPtr() on anything. Any ideas?