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{
	int* accessPtr(){
		return ptr;
	int* ptr;
class child1 : public parent{
	child1(int* somevalue){
		//initializes ptr to somevalue, a pointer to something stored elsewhere
class child2 : public parent{
		//initializes ptr using new
		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?

Without having lookin so closely at your code shouldnt
child2->accessPtd() be

Good point, though that mistake only appears in the code I typed here, not in my source. Edited.

It is somewhat difficult to know what you have in real code,
like your comment
//initialize ptr using new

Do you actually do this?

If you supply your full sourcecode it will be easier to help you

Sorry to all for making this topic, turns out I had forgotten to pass a value for the pointer to my constructor, and it was getting initialized to NULL (thanks to the default value I put there myself), and SIGSEGV is G++'s way of saying I tried to deref null.

to monkey_king: the header file for the classes is about 100 lines long, the .cpp file is 300 lines long, and of course the pointer is to another class which I implemented, which is another 70 or 80 lines. Therefore, I tried to narrow my source code to just the part that was giving me trouble.

This article has been dead for over six months. Start a new discussion instead.