从基本静态方法调用派生构造函数

时间:2019-08-26 19:51:20

标签: c++

我想知道是否有一种方法可以从在其基类上定义的静态方法实例化派生类。现在,我已经将方法包装在模板结构中。理想情况下,我想做这样的事情:

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();
}

0 个答案:

没有答案