我正在尝试将BOOST_FUSION_ADAPT_ADT应用于类,如下所示:
class XY {
private:
std::string x; // lhs
std::list<std::list<std::string>> y;
public:
std::list<std::list<std::string>> const &getY() const {
return y;
}
void setY(std::list<std::list<std::string>> const &y) {
this->y = y;
}
std::string const &getX() const { return x; }
void setX(std::string const &x) { this->x = x; }
};
但是,我收到以下错误,我无法完全弄清楚出什么问题了。xxxxxxxxxxxxxxx: error: no matching function for call to ‘Rule::setY(const std::__cxx11::basic_string<char>&)’
(std::list<std::list<std::string>> const&, std::list<std::list<std::string>> const&, obj.getY(), obj.setY(val))
^
xxxxxxxxxxxxxxx: note: candidate: void Rule::setY(const std::__cxx11::list<std::__cxx11::list<std::__cxx11::basic_string<char> > >&)
void setY(std::list<std::list<std::string>> const &y) {
最佳答案
您不播种您如何使用它。但是,当我尝试时没有问题:
Live On Compiler Explorer
#include <boost/fusion/adapted.hpp>
#include <boost/fusion/include/copy.hpp>
#include <string>
#include <list>
#include <fmt/ranges.h>
using namespace std::string_literals;
using Lists = std::list<std::list<std::string> >;
class XY {
private:
std::string x;
Lists y;
public:
void setY(Lists const& y) { this->y = y; }
void setX(std::string const& x) { this->x = x; }
[[nodiscard]] Lists const& getY() const { return y; }
[[nodiscard]] std::string const& getX() const { return x; }
};
BOOST_FUSION_ADAPT_ADT(XY,
(obj.getX(), obj.setX(val))
(obj.getY(), obj.setY(val))
)
int main() {
XY test;
boost::fusion::copy(
std::make_tuple("hello", Lists { {"world"s, "bye"s}, {"world"s} }),
test);
fmt::print("{}\n{}\n",
test.getX(),
test.getY());
}
版画hello
{{"world", "bye"}, {"world"}}
关于c++ - BOOST_FUSION_ADAPT_ADT找不到设置方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63033995/