#include <iostream>
#include <string>
using namespace std;
template <typename T,
typename T::type N,
typename T::strata& X>
struct SomeClass{};
struct S1
{
typedef int type;
typedef string strata;
};
int main() {
SomeClass<S1, 3, string("erg")> x;
}
失败消息:非类型模板参数没有引用任何声明?
g++ templ.cc -o templ -std=c++14 templ.cc:18:20: error: non-type template argument does not refer to any declaration SomeClass<S1, 3, string("erg")> x; ^~~~~~~~~~~~~ templ.cc:8:24: note: template parameter is declared here typename T::strata& X>
为什么它的工作原理为INT而不是字符串? 为什么它说该字符串是非类型的参数?
因为它不是一个类型。非类型参数仅限于基元(实际上,积分和指针) –
@PasserBy也可以使用此处所用的类类型引用。 – aschepler
而且...我没有看到那个参考:) –