【发布时间】:2015-08-07 13:38:46
【问题描述】:
我试图确定在 C++11 下使用私有继承时公开构造函数的两种方式之间的区别。
方法一:
class Base {
public:
int i;
Base(int x): i(x) {}
};
class Derived : private Base {
public:
Derived(int x) : Base(x) {} // constructor method 1
};
方法二:
class Base {
public:
int i;
Base(int x): i(x) {}
};
class Derived : private Base {
public:
using Base::Base; // constructor method 2
};
在表面测试中,两者的工作方式似乎相同。唯一真正的区别是我的代码编辑器(clion)似乎不喜欢后者。这里还有更多的故事吗?这些中的任何一个都明显更可取吗?
【问题讨论】: