64,684
社区成员
发帖
与我相关
我的任务
分享
template <typename T>
class X
{
public:
static void fun(const typename T::Z &z){}
};
class Y : public X<Y>
{
public:
class Z{};
};
int _tmain(int argc, _TCHAR* argv[])
{
Y y;
return 0;
}
template <typename Z>
static void fun(const Z &z)
{
static_assert(std::is_same<Z, typename T::Z>::value, "参数应为 T::Z 类型");
//...
}
定义class Y : public X<Y>时Y还是不完整类型,所以在实例化X<Y>时出错。利用static_assert将检查延后,但编写时稍有不便。