I am looking for a clean C ++ idiom for the following situation:
class SomeLibraryClass {
public:
SomeLibraryClass() { }
void addFoo() { }
void funcToCallAfterAllAddFoos() { }
};
class SomeUserClass : public SomeLibraryClass {
public:
SomeUserClass() {
addFoo();
addFoo();
addFoo();
}
};
class SomeUserDerrivedClass : public SomeUserClass {
public:
SomeUserDerrivedClass() {
addFoo();
}
};
So, I really want SomeLibraryClass to force a call to funcToCallAfterAllAddFoos at the end of the build process. The user cannot put it at the end of SomeUserClass :: SomeUserClass (), which will ruin SomeUserDerrivedClass. If it puts it at the end of SomeUserDerrivedClass, it will never be called for SomeUserClass.
To clarify what I need, imagine that / * run initialization * / gets a lock, and funcToCallAfterAllAddFoos () releases the lock.
The compiler knows when all the initializations for the object are complete, but can I get this information with some nice trick?