用字符串作为函数模版的实参

来源:互联网 发布:手机淘宝图片拍摄技巧 编辑:程序博客网 时间:2024/05/14 18:21

#include <typeinfo>
#include <iostream>
using namespace std;

template <typename T>
void ref(T const& x){
 cout<<"x in ref(T const&):"<<typeid(x).name()<<'/n';
}

template <typename T>
void nonref(T x){
 cout<<"x in nonref:       "<<typeid(x).name()<<'/n';
}

int main(){
    ref("hello");
    nonref("hello");
}


//输出结果:
//x in ref(T const&):char const [6]
//x in nonref:       char const *

原创粉丝点击