const字符串引用作为非类型模板参数

时间:2015-04-22 13:57:07

标签: c++ string templates gcc const-reference

我试图将const字符串引用作为非类型模板参数,我无法通过此编译错误。

test.h:

#include <string.h>
#include <iostream>

template<const std::string& V> class TestTmplt
{

};

const std::string& TEST_REF = "TESTREF" ;
typedef  TestTmplt<TEST_REF>  TestRefData ;

test.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

我在centos linux上编译,使用以下gcc命令

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

0 个答案:

没有答案
相关问题