Re: How can i force my derivers to call a base function
* ManicQin:
Hi lets say I have the next situation
class base
{
pubic: ;)
base() {}
virtual ~base(){}
virtual init()
{//do init }
};
now i want that every deriver will call MY init function before he
init his class...
for some reasons I cannot put those calls in the cTor...
one thing that I thought of is
class base
{
public:
init()
{
//do base's init
secondPhaseInit();
}
protected:
virtual secondPahseInit() = 0;
}
and then the deriver can only override secondPhaseInit and he needs to
go through my init .
But it's still not an idiot proof method... is there a way?
Your question is extremely unclear.
If it's just about how to achieve two-phase construction, the best is
probably to read up on class invariants in order to understand why that
is a generally a Bad Idea.
Otherwise, have a look at the FAQ, e.g. <url:
http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.6>.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?