由于错误LNK2005
,我的功能出现问题void createNetwork(Link **linkTable, Router **router, Computer **computer) {
router = new Router*[5];
linkTable = new Link*[11];
computer = new Computer*[6];
//---------------------------------------------------------------
router[0] = NULL;
//---------------------------------------------------------------
router[1] = new Router(1);
router[1]->link = new Link*[4];
....
错误:
1>device.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (? createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>Link.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (?createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>Packet.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (?createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>Queue.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (?createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>Router.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (?createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>sc.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (?createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>Time.obj : error LNK2005: "void __cdecl createNetwork(class Link * *,class Router * *,class Computer * *)" (?createNetwork@@YAXPAPAVLink@@PAPAVRouter@@PAPAVComputer@@@Z) already defined in Computer.obj
1>E:\Dokumenty\Symulacja - Projekt\trunk\f4_sk_zelek_wit\Debug\f4_sk_zw.exe : fatal error LNK1169: one or more multiply defined symbols found
我试图以某种方式修复它,但它没有工作。有人能告诉我该怎么做才能解决这个问题吗?谢谢:)
答案 0 :(得分:4)
如果要在标题中定义函数,请将其标记为inline
以允许每个翻译单元中包含标题的定义。
或者,将定义移动到源文件中,因此只定义一次。