我已经尝试了几个小时来编写一个派生自的类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*为stringint为longenum …