我显然误解了模板专业化的一些重要内容,因为:
template<typename type> const type getInfo(int i) { return 0; }
template<> const char* getInfo<char*>(int i) { return nullptr; }
无法编译:
src/main.cpp:19:24: error: no function template matches function
template specialization 'getInfo'
尽管
template<typename type> type getInfo(int i) { return 0; }
template<> char* getInfo<char*>(int i) { return nullptr; }
工作正常。如何使用const
模板专业化?我的菜鸟错误是什么?
我在 clang++ 上使用 c++11。