C ++ 11/14/17:模板类指针作为模板参数

时间:2017-10-08 12:50:09

标签: c++ c++11 templates

是否可以使用模板类指针声明模板函数?像这样:

template <typename FirstType, typename ... TypesRemaining>
class MyClass
{
  // ...
};

template <int n, template <typename FirstType, typename ... TypesRemaining> typename MyClass<FirstType, TypesRemaining...>::*ptr> myFunction() { 
  // ...
}

是否可以使用&#39;使用&#39;声明指针类型?像这样:

template <typename FirstType, typename ... TypesRemaining>
class MyClass
{
  // ...
};

template<typename FirstType, typename ... TypesRemaining>
using ptrMyClass = MyClass<FirstType, TypesRemaining...>*;

template <int n, template <typename FirstType, typename ... TypesRemaining> typename ptrMyClass<FirstType, TypesRemaining...> ptr> myFunction() { 
  // ...
}

1 个答案:

答案 0 :(得分:1)

你可以做这样的事情(用clang编译好,用gcc给ICE):

float totalHours = 0;
foreach(Person p in peopleList){
    totalHours += p.workedHours;
}

conditional expression [[ .. ]]