最小的工作示例:
#include <iostream>
struct Printer
{
template<class T>
static void print(T elem) {
std::cout << elem << std::endl;
}
};
template<class printer_t>
struct Main
{
template<class T>
void print(T elem) {
// In this case, the compiler could guess T from the context
// But in my case, assume that I need to specify T.
printer_t::print<T>(elem);
}
};
int main()
{
Main<Printer> m;
m.print(3);
m.print('x');
return 0;
}
我的编译器 (g++) 给了我错误"expected primary-expression before '>' token"。出了什么问题以及如何解决?
接受 C++11。