C++11 – Inherited constructors

Now C++11 allow that derived class can inherit the constructors of base class as the following.

class A
    A(int a) {}
    A(std::string const& str) {}
    A(double a, int f) {}

class B : public A
    using base::A;

However, you need to be careful when if B has any member variable, they will be initialized with random values unless you initialize specifically.

This entry was posted in C++, Programming. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s