Basically I want all sub-types to be created through a factory method (I have a tall domain hierarchy with some 200+ classes).
For new, it is not an issue since this can be overridden in A (making new private).
class A{
protected:
A();
public:
template<class T, typename... ARGUMENTS>
static T* create(ARGUMENTS&&... arguments);
};
class B : public A {
public:
B();
};
void test() {
B b;//compile error wanted here - but as a consequence of inheriting A
}
Here A is a the "library/framework" class. Whereas B is a "user created class". It might be ok to require a typedef or similar on B.
UPDATE: I added the 'create' function on A that I intent to use for creating objects.