Skip to main content
added 102 characters in body; added 16 characters in body
Source Link
UncleBens
  • 41.4k
  • 6
  • 62
  • 90

It's hard to tell anything definite without something compilable, but

const std::set<MyEdge*>& getEdges() { return edges; }; 

and

const std::pair<MyNode*, MyNode*>& getEndpoints() { return nodes; }; 

should technically be const methods since they don't modify the class and return a const reference.

const std::set<MyEdge*>& getEdges() const { return edges; }; const std::pair<MyNode*, MyNode*>& getEndpoints() const { return nodes; }; 

This in combination with const_iterator might solve your constness problems.


However, your particular error might be that *it->foo() = *(it->foo())is different from (*it)->foo()

It's hard to tell anything definite without something compilable, but

const std::set<MyEdge*>& getEdges() { return edges; }; 

and

const std::pair<MyNode*, MyNode*>& getEndpoints() { return nodes; }; 

should technically be const methods since they don't modify the class and return a const reference.

const std::set<MyEdge*>& getEdges() const { return edges; }; const std::pair<MyNode*, MyNode*>& getEndpoints() const { return nodes; }; 

This in combination with const_iterator might solve your constness problems.

It's hard to tell anything definite without something compilable, but

const std::set<MyEdge*>& getEdges() { return edges; }; 

and

const std::pair<MyNode*, MyNode*>& getEndpoints() { return nodes; }; 

should technically be const methods since they don't modify the class and return a const reference.

const std::set<MyEdge*>& getEdges() const { return edges; }; const std::pair<MyNode*, MyNode*>& getEndpoints() const { return nodes; }; 

This in combination with const_iterator might solve your constness problems.


However, your particular error might be that *it->foo() = *(it->foo())is different from (*it)->foo()

Source Link
UncleBens
  • 41.4k
  • 6
  • 62
  • 90

It's hard to tell anything definite without something compilable, but

const std::set<MyEdge*>& getEdges() { return edges; }; 

and

const std::pair<MyNode*, MyNode*>& getEndpoints() { return nodes; }; 

should technically be const methods since they don't modify the class and return a const reference.

const std::set<MyEdge*>& getEdges() const { return edges; }; const std::pair<MyNode*, MyNode*>& getEndpoints() const { return nodes; }; 

This in combination with const_iterator might solve your constness problems.