So I'm trying to code a GOAP AI behavior in C++. To do so I have to program a AStar Pathfinding algorithm and doing so i ran into this error:
Error C2678 binary '<': no operator found which takes a left-hand operand of type 'const _Ty' (or there is no acceptable conversion) SDL_Decisions
Showing in the compiler:
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xstddef(141): error C2678: binary '<': no operator found which takes a left-hand operand of type 'const _Ty' (or there is no acceptable conversion)
1> with
1> [
1> _Ty=State
1> ]
1>c:\users\computer\desktop\tercero_enti_ia\aa4\src\utils.h(75): note: could be 'const bool State::operator <(const State &)'
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\system_error(319): note: or 'bool std::operator <(const std::error_condition &,const std::error_condition &) noexcept'
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\system_error(312): note: or 'bool std::operator <(const std::error_code &,const std::error_code &) noexcept'
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xstddef(141): note: while trying to match the argument list '(const _Ty, const _Ty)'
1> with
1> [
1> _Ty=State
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xstddef(140): note: while compiling class template member function 'bool std::less<_Kty>::operator ()(const _Ty &,const _Ty &) const'
1> with
1> [
1> _Kty=State,
1> _Ty=State
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xutility(1110): note: see reference to function template instantiation 'bool std::less<_Kty>::operator ()(const _Ty &,const _Ty &) const' being compiled
1> with
1> [
1> _Kty=State,
1> _Ty=State
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xutility(264): note: see reference to class template instantiation 'std::less<_Kty>' being compiled
1> with
1> [
1> _Kty=State
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xutility(264): note: see reference to variable template 'const bool is_empty_v<std::less<State> >' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\xtree(1032): note: see reference to class template instantiation 'std::_Tree_comp_alloc<_Traits>' being compiled
1> with
1> [
1> _Traits=std::_Tmap_traits<State,int,std::less<State>,std::allocator<std::pair<const State,int>>,false>
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\map(82): note: see reference to class template instantiation 'std::_Tree<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>' being compiled
1> with
1> [
1> _Kty=State,
1> _Ty=int,
1> _Pr=std::less<State>,
1> _Alloc=std::allocator<std::pair<const State,int>>
1> ]
1>c:\users\computer\desktop\tercero_enti_ia\aa4\src\goap_astar.cpp(19): note: see reference to class template instantiation 'std::map<State,int,std::less<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>' being compiled
1> with
1> [
1> _Kty=State,
1> _Ty=int
1> ]
and my code looks like this:
void GOAP_AStar::run(Agent * agent, float dtime)
{
State initState = agent->bbData->GetState(bbVariables::STARTING_STATE);
State targetState = agent->bbData->GetState(bbVariables::OBJECTIVE);
std::map <State, int> costSoFar;
std::map <State, Actions> camefrom;
// Add the first node to frontier.
frontier.push(GOAPComparer(Actions("init",initState,initState), 0.0f));
costSoFar[(State)initState] = 0;
...
}
the line that makes the error come up is this one:
costSoFar[(State)initState] = 0;
And my struct State looks like this:
struct State
{
int alive;
int have_gun;
int gun_reloaded;
int has_bomb;
int enemy_visible;
int enemy_aligned;
int enemy_near;
int enemy_alive;
State()
{
}
State(int _alive, int _havegun, int _gunreloaded, int _hasbomb, int _enemyVisible, int _enemyAligned, int _enemyNear, int _enemyAlive)
{
alive = _alive;
have_gun = _havegun;
gun_reloaded = _gunreloaded;
has_bomb = _hasbomb;
enemy_visible = _enemyVisible;
enemy_aligned = _enemyAligned;
enemy_near = _enemyNear;
enemy_alive = _enemyAlive;
}
inline void operator=(const State& v2)
{
alive = v2.alive;
have_gun = v2.have_gun;
gun_reloaded = v2.gun_reloaded;
has_bomb = v2.has_bomb;
enemy_visible = v2.enemy_visible;
enemy_aligned = v2.enemy_aligned;
enemy_near = v2.enemy_near;
enemy_alive = v2.enemy_alive;
}
inline bool operator==(const State& v2)
{
return (alive == v2.alive || v2.alive == 2) &&
(have_gun == v2.have_gun || v2.have_gun == 2) &&
(gun_reloaded == v2.gun_reloaded || v2.gun_reloaded == 2) &&
(has_bomb == v2.has_bomb || v2.has_bomb == 2) &&
(enemy_visible == v2.enemy_visible || v2.enemy_visible == 2) &&
(enemy_aligned == v2.enemy_aligned || v2.enemy_aligned == 2) &&
(enemy_near == v2.enemy_near || v2.enemy_near == 2) &&
(enemy_alive == v2.enemy_alive || v2.enemy_alive == 2);
}
inline bool operator!=(const State& v2)
{
return !(*this == v2);
}
const bool operator <( const State& v2)
{
return
std::tie(this->alive, this->enemy_aligned, this->enemy_alive, this->enemy_near, this->enemy_visible, this->gun_reloaded, this->has_bomb, this->have_gun)
<
std::tie(v2.alive, v2.enemy_aligned, v2.enemy_alive, v2.enemy_near, v2.enemy_visible, v2.gun_reloaded, v2.has_bomb, v2.have_gun);
}
};
Thanks in advance for any help you can provide