c 语言 模板函数,函数模板特化
生活随笔
收集整理的這篇文章主要介紹了
c 语言 模板函数,函数模板特化
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
該樓層疑似違規已被系統折疊?隱藏此樓查看此樓
#include
#include
#include
using namespace std;
template
size_t bytes(T & t)
{
cout<
return sizeof t;
}
size_t bytes(char * & s)
{
cout<
return strlen(s)+1;
}
size_t bytes(wchar_t * & w)
{
cout<
return 2*(wcslen(w)+1);
}
template<>
size_t bytes<>(string & s)
{
cout<
return sizeof s;
}
template<>
size_t bytes(float & x)
{
cout<
return sizeof x;
}
void main()
{
int i;
cout<
char * s="hello";
cout<
wchar_t * w=L"good bye";
cout<
string t;
cout<
float x;
cout<
double y;
cout<
}
總結
以上是生活随笔為你收集整理的c 语言 模板函数,函数模板特化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据库设计思考
- 下一篇: c语言贪吃蛇运行代码,刚学C语言,想写一