gpt4 book ai didi

c++ - 未为使用默认模板参数声明的别名模板指定模板参数时出错

转载 作者:行者123 更新时间:2023-11-30 03:32:59 25 4
gpt4 key购买 nike

我试图让用户生成他们自己的存储类型,但我迷失了最后一个模板元函数。

基本存储类:

template < typename Data,
typename P1,
typename P2,
typename P3 >
struct Storage : P1, P2, P3 {};

元函数:

template < template <typename,typename> typename Container,
template <typename...> typename WrapperType,
template <typename> typename Allocator = std::allocator >
struct MetaStorage {

template < template <typename> typename P1,
template <typename> typename P2,
template <typename> typename P3 >
struct With_Policies {

template < typename ... Ts >
struct With_Types {

template < typename T = WrapperType<Ts...>,
typename Data = Container<T, Allocator<T>> >
using type = Storage<Data,
P1<Data>,
P2<Data>,
P3<Data>>;
};
};
};

用例:

template <typename ... T > struct DefaultWrapper {};

template < typename T > struct Policie1 {};
template < typename T > struct Policie3 {};
template < typename T > struct Policie2 {};

struct C1 {};
struct C2 {};

using Sig = MetaStorage<std::vector, DefaultWrapper>::With_Policies<Policie1, Policie2, Policie3>::With_Types<C1, C2>::type;

错误 g++ 6.3:

test.cpp: In function ‘int main()’: test.cpp:137:15: error: invalid  use of template-name ‘MetaStorage<std::vector,  DefaultWrapper>::With_Policies<Policie1, Policie2,  Policie3>::With_Types<C1, C2>::type’ without an argument list    using Sig = MetaStorage<std::vector,  DefaultWrapper>::With_Policies<Policie1, Policie2,  Policie3>::With_Types<C1, C2>::type;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test.cpp:58:37: note: ‘template<class T, class Data> using type = Storage<Data, Policie1<Data>, Policie2<Data>, Policie3<Data> >’ declared here
P3<Data>>;
^

最佳答案

type被声明为别名模板,那么这里需要模板参数。因为声明了默认参数,所以只需添加 <>为此,例如

using Sig = MetaStorage<std::vector, DefaultWrapper>::With_Policies<Policie1, Policie2, Policie3>::With_Types<C1, C2>::type<>;
// ~~

关于c++ - 未为使用默认模板参数声明的别名模板指定模板参数时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43304715/

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