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.
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 whatusing
is for, so usingusing
makes your intent clear to anyone using typeFooA
. On the other hand, creating a derived class will add unnecessary complexity and confusion.