C++11 adds a way to explicitly inherit base class constructors; e.g.:
class Base {
public:
Base(int, double) { ... }
Base(char*) { ... }
...
};
class Derived : public Base {
public:
// Similar to explicitly defining:
// Derived(int x, double y) : Base(x, y) {}
// Derived(char* z) : Base(z) {}
using Base::Base;
...
};
I'd like to see them allowed by the Chromium C++ style guide, but they're currently not listed at all on
chromium-cpp.appspot.com.
My use case is I have some typedefs for a class, but they're purely an implementation detail, so it seems unfortunate to need to define them in the header. As an alternative, I've found this seems to work nicely:
foo.h:
class Foo {
...
private:
struct FooKey;
FooKey MakeKey(...);
...
};
foo.cc:
#include "base/tuple.h"
struct Foo::FooKey : public Tuple4<X, Y, Z, W> {
using Tuple4<X, Y, Z, W>::Tuple4;
};
...
Then I don't need to include base/tuple.h or any headers necessary for declaring X/Y/Z/W in the header, and I don't need to add boilerplate passthrough constructors myself.