I want to use the dependent type in CRTP, but I get a compilation error.

Asked 1 years ago, Updated 1 years ago, 357 views

template<typename Derived>
US>structure S{
    using I = typename Derived::T;
};

structure D:S<D>{
    using T=int;
};

int main()
{
    DD;
    return 0;
}

How can I use D::T in S with the above source code?

c++ templates

2023-02-24 10:02

1 Answers

https://stackoverflow.com/questions/47606667/how-to-get-typename-defined-in-derived-from-base-class
I will share it with you as I thought it would be nice to refer to the link above.
I would appreciate it if you could tell me what's going on.

template<class T>
structure traps;

template<class Derived>
US>structure Base {
  typeef typename traps <Derived >::TT;
};

template<typename T_>
structureImpl:public Base<Impl<T_>>{
  typeef T_T;
};

template<typename T_>
structure traps<Impl<T_>>{
  typeef T_T;
};


usingSpecialImpl=Impl<int>

int main() {
    SpecialImplsi;
    
}


2023-02-24 18:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.