On Dec 19, 10:28 am, ManicQin <Manic...@gmail.comwrote:
On Dec 19, 10:12 am, Rahul <sam_...@yahoo.co.inwrote:
I probably misled you both because i called my function init.
The question is not about cTor or initialization in
particularly.
class base
{
public:
foo()
{ /do something - any thing!
goo();
}
protected:
Why protected, and not private?
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.
I'm not sure I understand. Which code are you talking about?
If client code doesn't call some particular function, there's
not much you can do about it. For that matter, he may not even
create an instance of your class. And the author of the derived
class shouldn't call your base class function; that would result
in endless recursion. Could you please give an exact example of
the type of error you're trying to avoid.
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34