为什么这个简单的Gecode示例无法编译?

我正在尝试学习gecode,并试图使找到的示例here起作用。

// To use integer variables and constraints
#include <gecode/int.hh>
// To make modeling more comfortable
#include <gecode/minimodel.hh>  // To use search engines
#include <gecode/search.hh>
// To avoid typing gecode:: all the time
using namespace gecode;

class SendmoreMoney : public Space {
 protected:
  IntVarArray x;

 public:
  SendmoreMoney() : x(*this,8,9) {
    IntVar s(x[0]),e(x[1]),n(x[2]),d(x[3]),m(x[4]),o(x[5]),r(x[6]),y(x[7]);
    rel(*this,s != 0);
    rel(*this,m != 0);
    distinct(*this,x);
    rel(*this,1000 * s + 100 * e + 10 * n + d + 1000 * m + 100 * o + 10 * r + e ==
            10000 * m + 1000 * o + 100 * n + 10 * e + y);
    branch(*this,x,INT_VAR_SIZE_MIN(),INT_VAL_MIN());
  }
  SendmoreMoney(SendmoreMoney& s) : Space(s) { x.update(*this,s.x); }
  virtual Space* copy() { return new SendmoreMoney(*this); }
  void print() const { std::cout << x << std::endl; }
};

int main() {
  SendmoreMoney* m = new SendmoreMoney;
  DFS<SendmoreMoney> e(m);
  delete m;
  while (SendmoreMoney s = e.next()) {
    s->print();
    delete s;
  }
}

我最终遇到以下编译错误。

error: no matching function for call to 'gecode::IntVarArray::update(SendmoreMoney&,gecode::IntVarArray&)'
   27 |             x.update(*this,s.x);
      |                                ^

error: invalid new-expression of abstract class type 'SendmoreMoney'
   30 |             return new SendmoreMoney(*this);
      |                

我不知道这些来源。 IntVarArray当然有一个更新函数,其第一个参数是Space对象,而SendmoreMoney继承自Space,那么问题是什么?该代码是我发现的示例的逐字记录,因此大概可以按原样工作。

GUDUNVHAI 回答:为什么这个简单的Gecode示例无法编译?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1259356.html

大家都在问