在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/C++/ c++初學(xué)者 ld報(bào)錯(cuò)問(wèn)題?

c++初學(xué)者 ld報(bào)錯(cuò)問(wèn)題?

我用c++寫(xiě)了一個(gè)簡(jiǎn)單的領(lǐng)接表小程序,編譯的時(shí)候報(bào)錯(cuò) 代碼如下

#include <iostream>
#include <list>

using namespace std;

class Network;
class Node{
private:
    int number; // 節(jié)點(diǎn)序號(hào)
    int infected_step; // 節(jié)點(diǎn)受感染時(shí)間
    bool is_infected; // 節(jié)點(diǎn)是否被感染
    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);
}

報(bào)錯(cuò)如下:

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)
回答
編輯回答
維她命

析構(gòu)函數(shù)忘定義了

2017年11月7日 07:58
編輯回答
萌面人

析構(gòu)函數(shù)沒(méi)有定義

2017年3月16日 17:08
編輯回答
若相惜

這應(yīng)該叫鏈接錯(cuò)誤吧。不是發(fā)生于編譯期。Node::~Node()在鏈接時(shí)找不到定義的地方

2017年11月20日 00:36