我试图将 const 字符串引用作为非类型模板参数,我无法克服这个编译错误。
测试.h:
#include <string.h>
#include <iostream>
template<const std::string& V> class TestTmplt
{
};
const std::string& TEST_REF = "TESTREF" ;
typedef TestTmplt<TEST_REF> TestRefData ;
测试.cpp:
#include <test.h>
template class TestTmplt<TEST_REF> ;
编译错误:
./test.h:10:34: error: could not convert template argument âTEST_REFâ to âconst string& {aka const std::basic_string<char>&}â
./test.h:10:49: error: invalid type in declaration before â;â token
我正在使用以下 gcc 命令在 centos linux 上编译
g++ -c -MMD -MF test.u -g -D_LINUX -std=c++03 -pthread -Wall -DVALGRIND -Wno-missing-field-initializers -z muldefs -I. -o test.o test.cpp