C++ template inheritance hides template parameters

  • A+
template <typename> struct B {     constexpr static int T = 5; };  template <int T> struct D : B<int> {     constexpr static int value = T; };  int main() {     std::cout << D<7>::value << std::endl; } 

As I have recently learned that template parameters of a template derived class gets checked after the names in the base class scope during lookup. That being said, is there anyway to qualify value to refer to the template parameter T in the derived class?


I'm not entirely sure I understand the question but I think decltype does what you want:

template <int T> struct D : B<decltype(T)> {     constexpr static decltype(T) value = T; }; 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: