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

Overriding class methods

P: n/a
Hi, I am trying to override a class method from a child class like the
following:
class ParentClass
{
public:
ParentClass();
virtual ~ParentClass();
virtual double someMethod (int)=0;
}
ParentClass::ParentClass()
{
someMethod(1);
}

class childClass::public ParentClass
{
public:
childClass(): ParentClass(){;}
double someMethod(int);
}

double childClass::someMethod(int num)
{
//do something meaningfull here
return 0;
}
int main()
{
childClass cld();
return 0;
}
now, this program will crash because someMethod is called from the
ParentClass constructor.

If someMethod is called outside, e.g.

ParentClass::ParentClass()
{

}

and

int main()
{
childClass cld();
cld.someMethod();
return 0;
}

it will work fine.
However, I want to be able to call the overriden method someMethod()
from the constructor. Is there a way around this problem?

Thank you
Vasileios

--
Posted via a free Usenet account from http://www.teranews.com

Mar 16 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.