Reading List

The Selfish Gene
The Psychopath Test: A Journey Through the Madness Industry
Bad Science
The Feynman Lectures on Physics
The Theory of Everything: The Origin and Fate of the Universe


ifknot's favorite books »

Sunday, 13 April 2014

Stuff about C++11 that I like... #1 Inherited Constructors

Inherited constructors make life easy.


Depending on your mood the (counter)intuitive scope behaviour of class members such that ordinary scope rules apply to class members. In particular, a member of a base class is not in the same scope as a member of a derived class.[1]

In C++03 this necessitated a lot of boiler plate code to lift up the base class constructors but in C++11 this lifting of base class constructors into the derived class scope is now easy-peasy with the using keyword. It makes for the effortless building of an exception class hierarchy:

#include "queue_exception.h"
namespace que {
struct queue_closed_exception: queue_exception {
using queue_exception::queue_exception; //ta-da!
};
}
view raw exception.cpp hosted with ❤ by GitHub

References: 


No comments:

Post a Comment