我想这取决于类型调用不同的功能于一身的模板功能不同的功能,例如:呼吁取决于类型
template<typename T>
T func() {
static_assert(std::is_same<T, int>::value || /* other allowed types */ , "Type not allowed");
T ret {};
// if T == int
funcInt(&ret);
// if T == /* other types */
/* other functions */
}
这种事可能吗?
我尝试这样做:
std::function< int(*T)> query;
if (std::is_same<T, int>::value) {
query = funcInt;
}
,但是这给了我一个错误:
error: 'T' does not refer to a value
我认为这应该是'std :: function < int(T*)>查询;',假设它是一个指向'T'参数的指针? – Niall 2014-10-10 07:58:27
糟糕!耻辱对我来说,我认为这是一些奇怪的模板错误... – gartenriese 2014-10-10 08:04:02
如果我正确地读了你,你仍然会有错误,因为你的查询不能存储具有不能转换为T * – 2014-10-10 08:06:40