我用c++写了一个简单的领接表小程序,编译的时候报错 代码如下
#include <iostream>
#include <list>
using namespace std;
class Network;
class Node{
private:
int number; // 节点序号
int infected_step; // 节点受感染时间
bool is_infected; // 节点是否被感染
friend class Network;
public:
Node(int val) {number = val; infected_step = -1; is_infected = false;};
~Node();
};
class Network{
private:
int network_size;
list<Node>* graph;
public:
Network(const int val);
~Network();
void print();
void addEdge(int number1, int number2);
void deleteEdge(int number1, int number2);
};
Network::Network(const int val){
network_size = val;
graph = new list<Node>[val + 1];
}
Network::~Network(){
delete[] graph;
}
void Network::addEdge(int number1, int number2){
Node node1(number1), node2(number2);
graph[number1].push_back(node2);
graph[number2].push_back(node1);
}
报错如下:
Undefined symbols for architecture x86_64:
"Node::~Node()", referenced from:
Network::addEdge(int, int) in test-07ef30.o
std::__1::__list_imp<Node, std::__1::allocator<Node> >::clear() in test-07ef30.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
析构函数忘定义了