I have class base
which only contains private default constructor and public deleted copy constructor, and nothing else.
class base {
private:
base() = default;
public:
base(const base&) = delete;
};
If I try to inherit from base
and create an instance of class derived
as below, g++ 4.8.2 doesn't compile my code but VC++ 2013 does.
class derived : public base {
private:
derived() = default;
};
derived x;
So, is it a bug in g++ or VC++ 2013 just ignored something?
Here's the complete code...
class base {
private:
base() = default;
public:
base(const base&) = delete;
};
class derived : public base {
private:
derived() = default;
};
derived x;
int main() {
}
... and g++ error message.
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;
^