如何解决为什么要实例化此模板类专业化?
在模板类的特化中,我调用了一个不应编译的函数,但在我看来这无关紧要,因为我将 166 South Africa
164 USA
134 Spain
119 Sweeden
115 France
97 Russia
95 UK
9 Ukraine
5 Ireland
dtype: object
作为模板参数传递,并且编译器不应在其中实例化该类第一名:
false
如果我传递 #include <iostream>
template <typename T>
struct outerstruct
{
template <bool b>
struct innerStruct
{
};
template<>
struct innerStruct<true>
{
using type = std::underlying_type_t<T>;
};
template<>
struct innerStruct<false>
{
};
innerStruct<false> member; // std::underlying_type_t cannot be called on a T,// even though that class shouldn't be instantiated
// because I'm passing false (or I think)
};
int main()
{
outerstruct<int> a;
}
参数,为什么 innerStruct<true>
被实例化并且编译器试图调用 underlying_type
?
对我来说非常令人困惑,我可以通过向 false
添加另一个模板参数,使其按照我想要的方式运行(即,让编译器忽略对 std::underlying_type_t
的调用),在这里我添加innerClass
:
U
第一个和第二个例子有什么区别?如果在第一个示例中我只调用了 #include <iostream>
template <typename T>
struct outerstruct
{
template <typename ExtraArg,bool b>
struct innerStruct
{
};
template<typename ExtraArg>
struct innerStruct<ExtraArg,true>
{
using type = std::underlying_type_t<T>;
};
template<typename ExtraArg>
struct innerStruct<ExtraArg,false>
{
};
//innerStruct<bValue> member;
innerStruct<int,true> member; // Now it's working as I expected,// I can pass int or whatever argument to ExtraArg
// and it compiles as long as I have 'false'
};
int main()
{
outerstruct<int> a;
}
innerStruct<true>
有什么业务被实例化
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。