如何从boost::enable_shared_from_this派生模板模板类
How to derive a template template class from boost::enable_shared_from_this?
如何从boost::enable_shared_from_this派生模板化类型的模板类?
template<template<class T> class Container>
class Myclass : public boost::enable_shared_from_this<?> {
};
这没有编译:
template<template<class T> class Container>
class Myclass : public boost::enable_shared_from_this<Myclass<Container<T> > > {
};
错误:"Myclass"不是模板类型。
由于您的类是由template-template参数模板化的,因此您应该简单地使用Containter
。
template<template<class> class Container>
class Myclass : public boost::enable_shared_from_this<Myclass<Container> >
{
};
通常以以下方式使用boost::enable_shared_from_this
class Myclass
: public boost::enable_shared_from_this<Myclass>
{
// ...
};
如果你有一个模板,它会更改为
template<class T>
class Myclass
: public boost::enable_shared_from_this<Myclass<T> >
{
// ...
};
其中Myclass<T>
是在其他上下文中用于声明的类型。您必须使用模板参数编写整个类名。缩写形式MyClass
仅允许在定义内部使用。
对于模板模板参数,您必须使用
template<template<class> class T>
class Myclass
: public boost::enable_shared_from_this<Myclass<T> >
{
// ...
};
这是ForEveRs的答案。
相关文章:
- 表示"accepting anything for this template argument" C++概念的通配符
- 为什么使用 "this" 指针调用派生成员函数?
- 使用 'this' 作为指向 CRTP 基类中派生类的指针
- 派生类型的dynamic_cast "this":什么时候合法?
- 受保护成员在派生类中"not declared in this scope"
- 当基类不是多态但派生时,"this"地址不匹配是
- C++,pthread和静态回调。 "this" 返回一个指针,指向派生的基类(第 2 部分)
- 在 QList 派生类的每个迭代器中将'this'作为第二个参数
- 为什么"this"在为派生类对象调用时无法访问基类方法中的派生类成员
- 由 sf::P acket 定义的运算符<<是否与 sf::P acket 派生类的 (*this) 一起工作?
- 解析公用派生基类模板中的函数模板名称时出错"Not declared in this scope"
- 使用 static_cast 处理混合(基础和派生)对象的向量是否存在性能风险?(又名 "it this a dumb idea?" )
- 删除虚拟派生类的this和位置new
- 从派生类调用时推断'this'指针类型?
- 在模板派生类中,为什么需要使用成员函数中的"this->"限定基类成员名称?
- 多态性返回派生的"this",从C++中的基类
- 将基类模板的“this”类型转换为其派生类
- c++的bad_cast异常将*this强制转换为派生模板类
- C++ 虚拟继承:在派生的初始值设定项列表中static_cast "this"虚拟父级
- 当您具有虚拟析构函数时,基类指针中的"delete this"是否会删除派生类对象?