- 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?

31st Aug 2022, 9:22 PM
ITDW
2 Answers
1st Sep 2022, 12:06 AM
Shadow
Shadow - avatar
+ 4
ITDW Please remove those 'c++++++++++' from tags ...
1st Sep 2022, 2:32 AM
Ipang