gpt4 book ai didi

构造函数中的 C++ 类型特征导致错误

转载 作者:太空狗 更新时间:2023-10-29 20:44:43 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Where and why do I have to put the “template” and “typename” keywords?

我想要一个接受单个参数的构造函数,并且仅当该参数的类型具有成员类型 ::t 时才启用,该成员类型必须是其他类型的子类型。我为此使用了类型特征,代码如下所示:

#include <type_traits>

struct Y{};

struct X{
//Only allow if T has a type member T::t which is a subtype of Y
template <typename T>
X(T* t, std::enable_if<std::is_base_of<Y, typename T::t>::value, int>::type e = 0){}
};

但是,g++ 提示如下:

test/test.cpp:8:75: error: ‘std::enable_if<std::is_base_of<Y, typename T::t>::value, int>::type’ is not a type

我做错了什么?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com