我想知道是否有一种方法可以从在其基类上定义的静态方法实例化派生类。现在,我已经将方法包装在模板结构中。理想情况下,我想做这样的事情:
class Base {
public:
Base(){}
virtual ~Base(){}
static void do_something() {
Base b(); // should call Derived() instead
// use our object
}
}
class Derived: public Base {
public:
Derived(): Base() {}
~Derived(){}
}
// The idea would be to use the derived static method like that
int main(){
Derived::do_something();
}