为什么在类模板中,模板参数必须具有相同的数字[重复]

问题描述 投票:0回答:0
template<unsigned p, unsigned d>
struct A
{
    static constexpr int x = 66;
};
template<unsigned p>
struct A
{
    static constexpr int x = 66;
};
int main()
{
    cout << A<3>::x << endl;  //template argument few
}

但是

template<unsigned p, unsigned d>
void printV()
{
    cout << 111 << endl;
}
template<unsigned p>
void printV()
{
    cout << 90<< endl;
}

int main()
{
    printV<3>(); //90
}

无法理解,为什么在函数模板中,代码可以运行,而在类模板中,代码不能运行

谁能告诉我原因

c++ templates
© www.soinside.com 2019 - 2024. All rights reserved.