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.

3
  • 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. Commented Jul 16, 2016 at 10:18
  • see here en.cppreference.com/w/cpp/language/default_constructor Commented Jul 16, 2016 at 10:18
  • Duplicate of stackoverflow.com/questions/6502828/…, please make a quick search on Google before posting! Commented Jul 16, 2016 at 10:18

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.