Ускорение: почему apply_visitor не работает в этом коде

Я получаю следующую ошибку компилятора:

/usr/include/boost/variant/variant.hpp:832:32: ошибка: не соответствует
вызов to (const StartsWith) (bool&)»

для следующего кода. Кто-нибудь знает почему?

#include "boost/variant/variant.hpp"#include "boost/variant/apply_visitor.hpp"
using namespace std;
using namespace boost;

typedef variant<bool, int, string, const char*> MyVariant;

class StartsWith
: public boost::static_visitor<bool>
{
public:
string mPrefix;
bool operator()(string &other) const
{
return other.compare(0, mPrefix.length(), mPrefix);
}
StartsWith(string const& prefix):mPrefix(prefix){}
};

int main(int argc, char **argv)
{
MyVariant s1 = "hello world!";
apply_visitor(StartsWith("hel"), s1); // << compiler error
return 0;
}

2

Решение

Вы должны предоставить операторы для каждого типа, объявленного в MyVariant,

3

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector