我正在创建一个无向图,每次我将邻居 A 添加到节点 BI 时,都必须将节点 B 添加为 A 的邻居,但我的方法不起作用。
Non-const lvalue reference to type 'Element *' cannot bind to a temporary of type 'Element *'
class Element
{
std::vector<Element *> m_neighbours;
private:
public:
void addNeighbour(Element*& neighbour)
{
m_neighbours.push_back(neighbour);
neighbour->addNeighbour(this);
}
};
- 怎么了?
- 最好的解决方法?