Notes-6:字符串常量作为模板参数

来源:互联网 发布:易语言外网聊天源码 编辑:程序博客网 时间:2024/05/20 00:38
#include <iostream>using namespace std;struct clsTest {    clsTest() { std::cout << "clsTest()" << std::endl; }    virtual ~clsTest() { std::cout << "~clsTest()" << std::endl; }};template<typename T, const char meta[]> // 必须使用const char[], 而不是const char*void tf1() {    T a;    std::cout << "tf1() " << meta << std::endl;}template<typename T, int i>void tf2() {    T a;    std::cout << "tf2() " << i << std::endl;}extern const char meta_clsTest[]; // 必须先externint main(){    std::cout << "字符串常量作为模板参数!" << std::endl;    tf2<clsTest, 666>();     tf1<clsTest, meta_clsTest>();     return 0;}const char meta_clsTest[] = "meta_clsTest"; // 再定义