今天使用模板特化所遇到的问题
2007-01-01 21:02
204 查看
template<class T>
void test(const T& t)
{
cout<<"void test(const T& t)"<<endl;
}
template<>
void test<int>(const int& x)
{
cout<<"void test(const int& x)"<<endl;
}
上述代码是可以在VS2005上编译通过的,另外一种写法是:
template<class T>
void test(const T& t)
{
cout<<"void test(const T& t)"<<endl;
}
template<>
void test(const int& x)//此处没有<int>
{
cout<<"void test(const int& x)"<<endl;
}
但是,如果写成这样:
template<class T>
void test(const T& t)
{
cout<<"void test(const T& t)"<<endl;
}
template<>
void test<const int&>(const int& x)
{
cout<<"void test(const int& x)"<<endl;
}
就会出现问题:
d:codejob est est est.cpp(19) : error C2770: invalid explicit template argument(s) for 'void test(const T &)'
d:codejob est est est.cpp(10) : see declaration of 'test'
d:codejob est est est.cpp(19) : error C2912: explicit specialization; 'void test<const int&>(const int &)' is not a specialization of a function template
void test(const T& t)
{
cout<<"void test(const T& t)"<<endl;
}
template<>
void test<int>(const int& x)
{
cout<<"void test(const int& x)"<<endl;
}
上述代码是可以在VS2005上编译通过的,另外一种写法是:
template<class T>
void test(const T& t)
{
cout<<"void test(const T& t)"<<endl;
}
template<>
void test(const int& x)//此处没有<int>
{
cout<<"void test(const int& x)"<<endl;
}
但是,如果写成这样:
template<class T>
void test(const T& t)
{
cout<<"void test(const T& t)"<<endl;
}
template<>
void test<const int&>(const int& x)
{
cout<<"void test(const int& x)"<<endl;
}
就会出现问题:
d:codejob est est est.cpp(19) : error C2770: invalid explicit template argument(s) for 'void test(const T &)'
d:codejob est est est.cpp(10) : see declaration of 'test'
d:codejob est est est.cpp(19) : error C2912: explicit specialization; 'void test<const int&>(const int &)' is not a specialization of a function template
相关文章推荐
- 今天学习使用mysql遇到的问题和解决办法
- 今天第一天使用DB2,遇到些问题
- 今天在MFC中使用listctrl虚拟列表遇到的一点问题
- 今天使用eclipse-hilos版本的开发项目遇到一些问题
- 今天使用VS2012遇到一个问题:"链接器工具错误 LNK2026 XXX模块对于 SAFESEH 映像是不安全的"
- 今天开始使用这个blog来记录我的学习中遇到的问题吧
- 今天使用xloadtree遇到了问题:(
- 今天使用PullToRefreshListView时遇到Item点击事件失效问题,特此记下解决办法
- 昨天使用xhEditor时遇到问题,今天来发发牢骚
- 今天使用VS2012遇到一个问题:"链接器工具错误 LNK2026 XXX模块对于 SAFESEH 映像是不安全的"
- 今天使用VS2012遇到一个问题:"链接器工具错误 LNK2026 XXX模块对于 SAFESEH 映像是不安全的"
- 今天使用VS2015遇到一个问题:"链接器工具错误 LNK2026 XXX模块对于 SAFESEH 映像是不安全的"
- 今天遇到的问题是tftpd的使用问题
- 今天在使用MQ时遇到的CCSID问题
- PopupWindow的使用细节以及今天遇到的小问题
- 关于VisualSVN安装以及使用时所遇到的问题
- cocoaPods使用中遇到的问题
- xcode8.1更新迭代上传遇到的问题(使用环信3.0)
- github 安装配置以及使用遇到的一些问题
- EDMA使用中遇到cache一致性的问题