vs的c语言程序出错,c – 如何修复vs2013上的C3848错误?

我正在尝试在VS2013上使用C实现最佳优先搜索.下面是代码.

//node for tree

struct Node

{

Node(std::string const& s, std::string const& p)

: state(s), path(p)

{}

const std::string state;

const std::string path;

};

//heuristic functor

struct ManhattanDistance

{

std::size_t operator()(std::string const& state, std::string const& goal)

{

std::size_t ret = 0;

for (int index = 0; index != goal.size(); ++index)

{

if ('0' == state[index])

continue;

auto digit = state[index] - '0';

ret += abs(index / 3 - digit / 3) + abs(index % 3 - digit % 3);// distance(row) plus distance(col)

}

return ret;

}

};

//functor to compare nodes using the heuristic function.

template

struct GreaterThan

{

explicit GreaterThan(HeuristicFunc h, std::string const& g = "012345678")

: goal(g), heuristic(h)

{}

bool operator()(Node const& lhs, Node const& rhs) const

{

return heuristic(lhs.state, goal) > heuristic(rhs.state, goal);

return true;

}

const std::string goal;

const HeuristicFunc heuristic;

};

在单元测试中测试此代码时,编译器抱怨:

Error 1 error C3848: expression having type ‘const ai::search::ManhattanDistance’ would lose some const-volatile qualifiers in order to call ‘size_t ManhattanDistance::operator ()(const std::string &,const std::string &)’

如何理解这个错误?怎么解决?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值