小编sem*_*maj的帖子

从派生构造函数调用基类方法

class Base {
    public:
    Base() {}

    void Foo(int x) {...}
};

class Derived : public Base {
    public:
    Derived(int args) {
        /* process args in some way */

        Foo(result);
    }
};
Run Code Online (Sandbox Code Playgroud)

Is it allowed to call a method of the base class in the constructor of the derived class? I would imagine this is fine as the Base object should be fully constructed, but I wanted to check just in case.

c++ methods constructor base

6
推荐指数
1
解决办法
3618
查看次数

标签 统计

base ×1

c++ ×1

constructor ×1

methods ×1