- 1
C++ templates with inheritance
Templates confuse me with classes You can do this: template <int N> class A { protected: int p_int = N; }; Int \/ here class B : A<5> { public: void print(){ std::cout << p_int << std::endl; } }; And no error. But template to a base class doesn’t. template <int N> class A { protected: int p_int = N; }; template <int N> // template to base class B : A<N> { public: void print(){ std::cout << p_int << std::endl; } }; And now an error?
2 Réponses
+ 4
You can find an explanation here:
https://isocpp.org/wiki/faq/templates#nondependent-name-lookup-members
+ 4
ITDW
Please remove those 'c++++++++++' from tags ...