1

非型テンプレート引数として 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

次の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
4

1 に答える 1