且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将字符串文字作为类型参数传递给类模板

更新时间:2021-12-05 22:24:22

对不起,C ++当前不支持将字符串文字(或真实文字)用作模板参数.

Sorry, C++ does not currently support the use of string literals (or real literals) as template parameters.

但是重新阅读您的问题,那是您在问什么?你不能说:

But re-reading your question, is that what you are asking? You cannot say:

foo <"bar"> x;

但是你可以说

template <typename T>
struct foo {
   foo( T t ) {}
};

foo <const char *> f( "bar" );