On Dec 19, 10:12 am, Rahul <sam_...@yahoo.co.in> wrote:
Could you specify the details of the reason?
Derived class constructor can invoke any of the visible base class
member functions, which is one of the reason for the base class
constructor to be invoked before that of derived class constructor...
Thank you rahul on that great introduction to c++ inheritence.
And thank you Alf.
I probably misled you both because i called my function init.
The question is not about cTor or initialization in particularly.
take the next snip
class base
{
public:
foo()
{ /do something - any thing!
goo();
}
protected:
virtual goo() = 0;
}
class derive : public base
{
protected:
goo()
{
//do something else...
}
}
int main()
{
derive a;
a.foo(); //first base.foo() will execute and then derive.goo()
return 0;
}
the problem is that this pattern (I think they call it Template
Method) is not IDIOT PROOF.
tomorrow a coder would come and change my code so he would'nt call my
base function. (infact it happened today in spite of all the comments
i left!) I'm just looking for a different way to implement this.
You cannot prevent malice. Severly discipline the other developer for
breaking the design without consulting the appropriate stakeholders.