Default constructor/destructor in NonCopyable class

Here is a compiling piece of code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#ifndef NONCOPIABLE_H_
#define NONCOPIABLE_H_

class NonCopiable
    {
    protected:
        NonCopiable() {};
        ~NonCopiable() {};

    private:
        NonCopiable& operator=(const NonCopiable&) = delete;
        NonCopiable(const NonCopiable&) = delete;
    };

#endif // NONCOPIABLE_H_ 


It defines a class to inherit from which can't be copied (note that this version only works on C++11 and later). If I remove the default constructor/destructor definition it still compiles on it's own, but if I try to inherit from it, compilation fails.

My question is this: doesn't the compiler provide two default functions for these?

Thanks
Last edited on
> doesn't the compiler provide two default functions for these?

There would be an implicitly-declared default constructor (if possible) if and only if there are no user-declared constructors (of any kind).

Here, NonCopiable has a user-declared deleted copy constructor; and so it would not have an implicitly-declared default constructor. The compiler would have provided an implicitly-declared (public) destructor for the class if there was no user-declared destructor.
Thanks!
Topic archived. No new replies allowed.