C++ `using` keyword vs derived class

67 Views Asked by At

We have a templated type Foo<T>. In the codebase, it's 99% instantiated with a couple of types, and I would like to use a distinct name for those cases.

What are the pros/cons of the using keyword (using FooA = Foo<A>) vs declaring an empty derived class (class FooA : public Foo<A> {};)

It seems that the derived class is smoother to use (allow forward declaration), but I wonder about any performance (speed or memory) cost.

1

There are 1 best solutions below

0
On

I would not use a derived class in this situation, unless you need to add additional data members or member functions to FooA.

All you are really doing here is creating an alias for a specific instantiation of the Foo<T> template. This is exactly what using is for, so using using makes your intent clear to anyone using type FooA. On the other hand, creating a derived class will add unnecessary complexity and confusion.