base
私は、プライベートデフォルトコンストラクターとパブリック削除コピーコンストラクターのみを含むクラスを持っています。
class base {
private:
base() = default;
public:
base(const base&) = delete;
};
base
以下のようにクラスのインスタンスを継承して作成しようとするとderived
、g++ 4.8.2 ではコードがコンパイルされませんが、VC++ 2013 ではコンパイルされます。
class derived : public base {
private:
derived() = default;
};
derived x;
それで、それはg ++またはVC ++ 2013のバグで、何かを無視しただけですか?
これが完全なコードです...
class base {
private:
base() = default;
public:
base(const base&) = delete;
};
class derived : public base {
private:
derived() = default;
};
derived x;
int main() {
}
...そしてg ++エラーメッセージ。
main.cpp:12:5: error: 'constexpr derived::derived()' is private
derived() = default;
^
main.cpp:15:9: error: within this context
derived x;
^
main.cpp: In constructor 'constexpr derived::derived()':
main.cpp:3:5: error: 'constexpr base::base()' is private
base() = default;
^
main.cpp:12:5: error: within this context
derived() = default;
^
main.cpp: At global scope:
main.cpp:15:9: note: synthesized method 'constexpr derived::derived()' first required here
derived x;
^