typedef

Call explicit constructor/destructor with traits in templatized function

跟風遠走 提交于 2021-01-28 19:59:51
问题 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

typedef and template parameter with same name

安稳与你 提交于 2021-01-26 22:29:36
问题 Why is that case incorrect (it's logical) template <typename T> struct Der: public Base { typedef int T; T val; }; , but that case is correct? struct Base { typedef int T; }; template <typename T> struct Der: public Base { T val; }; The Standard 14.6.1/7 says: In the definition of a class template or in the definition of a member of such a template that appears outside of the template definition, for each base class which does not depend on a template-parameter (14.6.2), if the name of the

C++之typedef 小记

£可爱£侵袭症+ 提交于 2021-01-14 06:13:15
 以前曾不知道为何要用typedef,随着开发的深入,真正感受到了其内涵所在: 1.如:typedef int DataType 接下来项目中的几万行代码中,如果需要将所有的DataType改为float型,如果不用typedef工作量可想而知的;从而起到了精简代码的作用; 2.如下: typedef struc DataStru{ ........ ........ }MydataStru,*pMydataStru; 当你再定义数据结构时,如果是结构体,直接MydataStru就OK; 如果是结构体指针,直接pMydataStru就OK; 是不是简化你的程序了;其他过去赘余的例子不再举了,重在用心领悟; 哲学感悟:C++蕴含了太多的 哲学,存在就有其合理性 来源: oschina 链接: https://my.oschina.net/u/2344808/blog/397848

template base class typedef members invisible

馋奶兔 提交于 2020-12-19 15:13:38
问题 I'm aware of the fact that the 'dependent names' are not visible to the compiler by default. But I was told in answers to other SO questions (here, here, and ultimately on the C++ faq) that a using declaration may help. So I tried. A template base class: // regardless of the fact that members are exposed... template<typename T> struct TBase { typedef T MemberType; MemberType baseMember; MemberType baseFunction() { return MemberType(); } }; And a derived class, using the base's members:

template base class typedef members invisible

拥有回忆 提交于 2020-12-19 15:07:31
问题 I'm aware of the fact that the 'dependent names' are not visible to the compiler by default. But I was told in answers to other SO questions (here, here, and ultimately on the C++ faq) that a using declaration may help. So I tried. A template base class: // regardless of the fact that members are exposed... template<typename T> struct TBase { typedef T MemberType; MemberType baseMember; MemberType baseFunction() { return MemberType(); } }; And a derived class, using the base's members: