我在定义和专门化成员函数时遇到困难update()
内部类的Outer<T1>::Inner
这是在非类型(枚举)参数上模板化的。
#include <cstdlib>
template<typename T1>
struct Outer
{
struct Inner
{
enum Type{ A , B , C };
template<Type T2>
void update();
};
};
// Definition
template<typename T1>
template<Outer<T1>::Inner::Type T2>
void Outer<T1>::Inner::update()
{
}
// Specialization
template<typename T1>
template<Outer<T1>::Inner::A >
void Outer<T1>::Inner::update()
{
}
int main()
{
return EXIT_SUCCESS;
}
我在 GCC 4.5.3 中收到以下错误消息
prog.cpp:17:28: error: ‘Outer::Inner::Type’ is not a type
prog.cpp:18:6: error: prototype for ‘void Outer<T1>::Inner::update()’ does not match any in class ‘Outer<T1>::Inner’
prog.cpp:11:15: error: candidate is: template<class T1> template<Outer<T1>::Inner::Type T2> void Outer<T1>::Inner::update()
prog.cpp:24:28: error: ‘Outer::Inner::A’ is not a type
prog.cpp:25:6: error: prototype for ‘void Outer<T1>::Inner::update()’ does not match any in class ‘Outer<T1>::Inner’
prog.cpp:11:15: error: candidate is: template<class T1> template<Outer<T1>::Inner::Type T2> void Outer<T1>::Inner::update()
顺便说一句,与 GCC 不同,Visual Studio 2008 无法编译以下内容
template<typename T1>
struct Outer
{
struct Inner
{
enum Type{ A , B , C };
template<Type T2>
struct Deep;
};
};
template<typename T1>
template<typename Outer<T1>::Inner::Type T2>
struct Outer<T1>::Inner::Deep
{
};
首先,你缺少一个typename
before Outer<T1>::Inner::Type
。你必须拥有它,即使是在一个template
输入列表,因为Type
是依赖类型。
其次,您的专业化语法是错误的(类型进入<>
函数名之后,括号之前,而不是在template<>
),但即使它是正确的,它也不合法。你必须专门化外部模板Outer
在你完全专业化之前update
,根据关于显式模板专业化的不幸规则。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)