#include <string>
#include <iostream>
using namespace std;
class A
{
public:
template<typename T> void add_extend(const std::string &key,const T &value)
{
std::string ss = key;
ss += std::to_string(value);
std::cout<<ss<<endl;
std::cout<<"template<typename T> void add_extend(const std::string &key,const T &value)"<<endl;
}
void add_extend(const std::string &key,const std::string &value)
{
std::string ss = key;
ss += (value);
std::cout<<ss<<endl;
std::cout<<"void add_extend(const std::string &key,const std::string &value)"<<endl;
}
void add_extend(const std::string &key,const char *value)
{
std::string ss = key;
ss += (value);
std::cout<<ss<<endl;
std::cout<<"void add_extend(const std::string &key,const char *value)"<<endl;
}
};
int main(int argc,char * argv[])
{
A a;
std::string s = "模板特化-";
a.add_extend<int32_t>(s,11);
a.add_extend<long>("测试-",11);
a.add_extend<bool>("测试-",true);
a.add_extend<int32_t>("测试-",11);
a.add_extend(s,s);
a.add_extend(s,"重载");
return 0;
}
[test]# g++ -std=gnu++11 -g test.cpp -o test;./test
模板特化-11
template<typename T> void add_extend(const std::string &key,const T &value)
测试-11
template<typename T> void add_extend(const std::string &key,const T &value)
测试-1
template<typename T> void add_extend(const std::string &key,const T &value)
测试-11
template<typename T> void add_extend(const std::string &key,const T &value)
模板特化-模板特化-
void add_extend(const std::string &key,const std::string &value)
模板特化-重载
void add_extend(const std::string &key,const char *value)