C++ 与模板类一起使用的自定义模板参数绑定器
我有一个包含3个参数的模板类,我需要在之前绑定其中的2个参数,然后将绑定的版本传递给我继承的“父”C++ 与模板类一起使用的自定义模板参数绑定器,c++,templates,inheritance,arguments,bind,C++,Templates,Inheritance,Arguments,Bind,我有一个包含3个参数的模板类,我需要在之前绑定其中的2个参数,然后将绑定的版本传递给我继承的“父”template模板类。 (我已经搜索了以前提出的问题,但没有人试图从父项继承。) 我怎样才能让它工作 下面是一个示例代码: template <template<class> class W, class ...D> struct Parent{}; template <class B, class T, class ...D> struct Arg{};
template模板类。
(我已经搜索了以前提出的问题,但没有人试图从父项继承。)
我怎样才能让它工作
下面是一个示例代码:
template <template<class> class W, class ...D>
struct Parent{};
template <class B, class T, class ...D>
struct Arg{};
template <class B, class ...D>
struct Bind{
template <class T>
using arg = Arg<B, T, D...>;
};
template <class B, class ...D>
struct DD : public Parent<Bind<B, D...>::t, D...> //compiler complains*
{ };
* template argument for template template parameter must be a class template or type alias template.
模板
结构父{};
模板
结构Arg{};
模板
结构绑定{
模板
使用arg=arg;
};
模板
结构DD:公共父级//编译器投诉*
{ };
*模板参数的模板参数必须是类模板或类型别名模板。
我试过使用typename
关键字;在Binder
中使用struct
继承而不是using指令
,没有任何效果。首先,您可能指的是Bind::arg
而不是代码段中的Bind::t
其次,您需要template
关键字,因为Bind
是一个依赖于类型的id表达式。即
模板
结构DD:公共父级
{ };
首先,您可能是指代码段中的Bind::arg
而不是Bind::t
其次,您需要template
关键字,因为Bind
是一个依赖于类型的id表达式。即
模板
结构DD:公共父级
{ };
欢迎来到StackOverflow!欢迎来到StackOverflow!
template <class B, class ...D>
struct DD : public Parent<Bind<B, D...>::template arg, D...>
{ };