Call explicit constructor/destructor with traits in templatized function
问题 I'm trying to call explicit constructor/destructor with traits in templatized function. template <int i> struct Traits { }; template <> struct Traits<1> { typedef Foo type_t; }; template <> struct Traits<2> { typedef Bar type_t; }; template <class Traits> void DoSomething(void* p_in) { typename Traits::type_t* p = reinterpret_cast<typename Traits::type_t*>(p_in); // this works. new (p) typename Traits::type_t; // neither of following two does work. p->~typename Traits::type_t(); p->typename