相关疑难解决方法(0)

如何实现boost :: variant派生类?

我已经尝试了几个小时来编写一个派生自的类boost::variant.但我不明白是什么问题(我不明白编译错误意味着什么).

实现干净boost::variant派生类的规则是什么?

#include <boost/variant.hpp>

class MyVariant : public boost::variant<char,bool>
{
public:    
       MyVariant ()          : boost::variant<char,bool>( ) {}

       template <typename T>
       MyVariant(      T& v) : boost::variant<char,bool>(v) {}

       template <typename T>
       MyVariant(const T& v) : boost::variant<char,bool>(v) {}
};

int main ()
{
      MyVariant a;
      MyVariant b = a;        //compilation error
  //  MyVariant c = MyVariant();
  //  MyVariant d (true);
  //  MyVariant e ('E');
}
Run Code Online (Sandbox Code Playgroud)

为什么我要使用继承?(编辑给@zaufi更多细节)

  • 我想要一个空状态
  • 我想接受const char*string
  • 我想接受intlong
  • 我想给出enum …

c++ gcc boost derived-class boost-variant

7
推荐指数
1
解决办法
2244
查看次数

标签 统计

boost ×1

boost-variant ×1

c++ ×1

derived-class ×1

gcc ×1