En mi código estoy haciendo un grafo donde voy guardando estados y tengo que, como es logico, interconectarlos todos. Ya he repetido el código como 4 veces y siempre me da el mismo error. El codigo es el siguiente:
grafo.hpp
#ifndef _boii_
#define _boii_
#include <set>
#include "state.hpp"
using namespace std;
class grafo{
private:
set<state> my_states;
public:
grafo();
~grafo();
void set_states(int i);
};
#endif
grafo.cpp
#include "grafo.hpp"
grafo::grafo(){}
grafo::~grafo(){}
void grafo::set_states(int i){
state a;
a.set_id(i);
my_states.insert(a);
}
y nodo.hpp
#ifndef _qwerty_
#define _qwerty_
#include <vector>
#include <iostream>
using namespace std;
class state{
private:
int id;
bool acepted;
public:
state();
~state();
int get_id();
bool get_acpt();
void set_id(int i);
void set_acpt(bool i);
int operator < (const state& a);
};
#endif
del objeto nodo solo mostrare el operator, ya que es donde esta dando el error, y ademas que el resto de librerias son simples sets y gets. el perator < seria :
int state::operator < (const state& a){
if(id < a.id){
return 1;
}
return 0;
}
Por ultimo el error que me sale siempre es este :
In file included from /usr/include/c++/4.8/bits/stl_tree.h:63:0,
from /usr/include/c++/4.8/set:60,
from grafo.hpp:6,
from grafo.cpp:1:
/usr/include/c++/4.8/bits/stl_function.h: In instantiation of ‘bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = state]’:
/usr/include/c++/4.8/bits/stl_tree.h:1324:11: required from ‘std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = state; _Val = state; _KeyOfValue = std::_Identity<state>; _Compare = std::less<state>; _Alloc = std::allocator<state>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::key_type = state]’
/usr/include/c++/4.8/bits/stl_tree.h:1377:47: required from ‘std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(const _Val&) [with _Key = state; _Val = state; _KeyOfValue = std::_Identity<state>; _Compare = std::less<state>; _Alloc = std::allocator<state>]’
/usr/include/c++/4.8/bits/stl_set.h:463:29: required from ‘std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = state; _Compare = std::less<state>; _Alloc = std::allocator<state>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Key>, _Compare, typename _Alloc::rebind<_Key>::other>::const_iterator = std::_Rb_tree_const_iterator<state>; std::set<_Key, _Compare, _Alloc>::value_type = state]’
grafo.cpp:12:23: required from here
/usr/include/c++/4.8/bits/stl_function.h:235:20: error: passing ‘const state’ as ‘this’ argument of ‘int state::operator<(const state&)’ discards qualifiers [-fpermissive]
{ return __x < __y; }
^
state.cpp:26:38: error: no ‘int state::operator<(const state&)’ member function declared in class ‘state’
int state::operator < (const state& a){
^
Realmente agradeceria cualquier ayuda,y gracias por adelantado.