0

It's a syntax I've never seen in C++.

See the following:

class View
{
    private:
    int screenSize;
    int screenScale; //"the ZOOM"
    Point origin;
public:
    const int minScreenSize = 6;
    const int maxScreenSize = 30;

    View():screenSize(25),screenScale(2),origin(-10,-10){}
    ~View() = default;
    View(const View&) = default;
    View(View&&) = default;
    View& operator=(const View&) = default;
    View& operator=(View&&) = default;
    View& myAdd() = delete;
}

What is the meaning of:

View() = default and View() = delete?

Thanks in advance.

Billie
  • 8,938
  • 12
  • 37
  • 67
  • `Constructor() = default;` means that you explicitly want the compiler to generate the default constructor for that class `Constructor() = delete;` means that you explicitly forbid the usage of that constructor. – adnan_e Jul 16 '16 at 10:18
  • see here http://en.cppreference.com/w/cpp/language/default_constructor – Alexander Stepaniuk Jul 16 '16 at 10:18
  • Duplicate of http://stackoverflow.com/questions/6502828/what-does-default-mean-after-a-class-function-declaration, please make a quick search on Google before posting! – Sylvain B Jul 16 '16 at 10:18

1 Answers1

0

It tells the compiler to generate a default "default constructor" for your class.

This was introduced in C++11.

The counterpart is = delete; which would instruct the compiæer to not generate the function.

= default; is preferable to an empty user defined consteuctor {} since used defined destructors are never trivial by definition (even when they are empty), but the compiler generated function is.

More detail here:

http://en.cppreference.com/w/cpp/language/member_functions#Special_member_functions

http://en.cppreference.com/w/cpp/language/default_constructor

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70