TIL C++11!

Just a quick post to write about something mildly important to know.

Are you not defining your own copy constructors / assignment operators for each and every single class you do? (Kudos! Waste of time TM + unexpected behaviors / bugsources!)

Stop defining empty destructors!
STAHP!

At least for me, the standard is to have a standard create class macro / template, and this includes an empty destructor.
Especially since visual studios create class creates the constructor and the destructor empty for you as base.
Up until C++11, this has not been a problem.

But now! With C++11 the new and cool move constructor is not autogenerated if you have an empty destructor!

If you didn’t know the rules for auto generating move constructors: ”No user-declared copy constructor, copy assignment operator or destructor. Also breaks if any of the auto generated ones are invalid.”

Basically no-nos if you want a auto generated move constructor are:
Class::Class(const Class& other)
Class& operator=(const Class& other)
Class::~Class()

Here’s a clipping of some of my tests http://imgur.com/pS8Xnql

Yeah! TIL!

Hatshatsgabengaben,
Jonkel

Comments (1)

  1. 01:03, 1 april, 2013r2p2  / Svara

    How about virtual destructors?

Kommentera

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Pingbacks (0)

› No pingbacks yet.