我弄清楚为什么我似乎无法让std :: vector :: erase使用我自己的类对象的向量.下面的代码抛出一个"没有可行的重载'='"错误,并且无法弄清楚为什么经过一些广泛的搜索溢出/ tutorialspoint/...
我的类定义'MyClass.hpp':
#include <string>
#include <vector>
class node;
class graph{
public:
graph();
std::vector<node> nodeList;
};
class node{
public:
node(std::string name) : name(name){};
void operator=(node& rhs);
std::string name;
std::vector<node> adjacent;
};
void node::operator=(node& rhs){
name = rhs.name;
adjacent = rhs.adjacent;
}
Run Code Online (Sandbox Code Playgroud)
和我的主文件:
#include "MyClass.hpp"
int main(int argc, const char * argv[]) {
node node1("root"), node2("leaf");
node1.adjacent.push_back(node2);
node2.adjacent.push_back(node1);
node1.adjacent.erase(node1.adjacent.begin());
graph myGraph;
return 0;
}
Run Code Online (Sandbox Code Playgroud)