By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,605 Members | 1,488 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,605 IT Pros & Developers. It's quick & easy.

using non-default constructor with inheritence

P: n/a
Here is a simple version of my classes.

class BaseClass
{
protected:
BaseClass *myParent;
public:
BaseClass(BaseClass *parent);
virtual ~BaseClass();
};

class DerivedClass : BaseClass
{
public:
DerivedClass(BaseClass * parent);
virtual ~DerivedClass();
};

BaseClass::BaseClass(BaseClass *parent)
{
myParent = parent;
}

BaseClass::~BaseClass()
{
// clean up
}

DerivedClass::DerivedClass(BaseClass * parent):BaseClass(*parent)
{
// init derived class
}

DerivedClass::~DerivedClass()
{
// clean up
}

////
instantiation is:
DerivedClass *test = new DerivedClass(NULL);

Everything compiles but when I try and execute, I get an access
violation. Do you see what I have done wrong?

Thanks,
Eric

Nov 15 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
nt*******@sneakemail.com wrote:
Here is a simple version of my classes.

[..]
DerivedClass::DerivedClass(BaseClass * parent):BaseClass(*parent)
You probably meant

... : BaseClass(parent)
{
// init derived class
}
[..]

Everything compiles but when I try and execute, I get an access
violation. Do you see what I have done wrong?
You attempt to dereference a null pointer.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Nov 15 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.