Some time ago, I wrote about how injected class names were the C++ feature you didn’t even realize that you were using. Injected class names let you use the plain name for the class being defined without needing to fully qualify it with namespaces and template parameters. Furthermore, injected class names are public and can be inherited.
“But wait, I’m trying to use the injected class name of my base class, but the compiler won’t accept it.”
Why Can’t I Find the Injected Name of a Templated Class’s Templated Base Class?
by Raymond Chen
From the article:
Some time ago, I wrote about how injected class names were the C++ feature you didn’t even realize that you were using. Injected class names let you use the plain name for the class being defined without needing to fully qualify it with namespaces and template parameters. Furthermore, injected class names are public and can be inherited.
“But wait, I’m trying to use the injected class name of my base class, but the compiler won’t accept it.”
template<typename T> struct Base { Base(T value); }; template<typename T> struct Derived : Base<T> { Derived(T value) : Base(value) {} };This generates a compiler error.
Add a Comment
Comments are closed.