【发布时间】:2014-05-08 18:56:22
【问题描述】:
我需要使用模板类对我的函数进行专门化,并且遇到“非法使用显式模板参数”的问题。
template <typename T>
class MyClass { /* ... */ }; // it can be any template class, eg std::vector
template <typename T>
void foo() { /* ... */ } // my template function which need a specialization
template<>
void foo<int>() /* sth special for integers - it works */ }
template<template T>
void foo<MyClass<T> >() /* sth special for template class with any parameter - it doesnt work :( */ }
当然,我可以为我需要的所有 MyClass 键入一些专业化,但也许可以用一个来代替?
【问题讨论】:
标签: c++ templates template-specialization