2013-03-14 52 views
2

我試圖解決一個無法解析的外部(link2019錯誤)。在StackOverflow上有很多關於這個問題的帖子,但是我不瞭解錯誤或者我對此不以爲意。無法解析的外部鏈接2019混淆

錯誤是由我generate_maze功能引起的(具體由rand_neighbor()調用,對吧?),但我的理解是,這是所有的「解決」。

我截斷碼一點點,因爲它是相當冗長。我希望這是適當的。

void generate_maze (Vector<int> &coords, Grid<bool> &included, Maze &m); 

int main() { 

    Grid<bool> included = initialize_grid(); 
    Vector <int> coords = rand_coords(); 
    Vector <int> current_point = coords; 

    generate_maze(coords, included, m); 
    return 0; 
} 

void generate_maze (Vector<int> &coords, Grid<bool> &included, Maze &m) { 
    while (gridIsTrue == false) { 
    Vector<int> neighbor = rand_neighbor(coords, included); 
    pointT neighborpoint = {neighbor[0], neighbor[1]}; 
    pointT current_point = {coords[0], coords[1]}; 
    if (included.get(neighbor[0], neighbor[1]) == false) {m.setWall(current_point, neighborpoint, false); included.set(neighbor[0], neighbor[1], true); current_point = neighborpoint;} 
    } 
} 

Vector<int> rand_neighbor(Vector<int> &coords, Grid<bool> &included) { 
    while (1) { 
     int randomint; 
     randomint = randomInteger(1,4); 
     if (randomint == 1) {if (included.inBounds(coords[0], coords[1]+1)) {coords[1] = coords[1]+1; break;}} 
     if (randomint == 2) {if (included.inBounds(coords[0], coords[1]-1)){coords[1] = coords[1] -1; break;}} 
     if (randomint == 3) {if (included.inBounds(coords[0] -1, coords[1])){coords[0] = coords[0] -1; break;}} 
     if (randomint == 4) {if (included.inBounds(coords[0] +1, coords[1])){coords[0] = coords[0] + 1; break;}} 
       } 
     return coords; 

錯誤:

error LNK2019: unresolved external symbol "class Vector<int> __cdecl rand_neighbor(class Vector<int>,class Grid<bool> &)" ([email protected]@[email protected]@@[email protected][email protected][email protected]@@Z) referenced in function "void __cdecl generate_maze(class Vector<int> &,class Grid<bool> &,class Maze &)" ([email protected]@[email protected]@@[email protected][email protected]@[email protected]@@Z) 
1>C:\Users\com-user\Desktop\New folder\maze\assign3-maze-PC\Maze\Debug\Maze.exe : fatal error LNK1120: 1 unresolved externals 
+1

錯過包含或定義rand_neighbor()這裏有一點幫助http://stackoverflow.com/questions/9928238/unresolved-external-symbol-no-idea – Gilad 2013-03-14 22:48:50

回答

4

使用漂亮的網頁C++ demangler here你可以看到你未定義的參考[email protected]@[email protected]@@[email protected][email protected][email protected]@@Z實際上意味着class Vector __cdecl rand_neighbor(class Vector,class Grid &)。您的錯誤消息中缺少參數。

現在,你看到的宣言和你的函數的定義之間的區別?

class Vector __cdelc rand_neighbor(class Vector,class Grid &); 
Vector<int> rand_neighbor(Vector<int> &coords, Grid<bool> &included) { /* ... */} 

讓我歸他們一點:

Vector<int> rand_neighbor(Vector<int>, Grid<bool> &); 
Vector<int> rand_neighbor(Vector<int> &, Grid<bool> &) { /* ... */} 

你忘了在函數原型的引用(&)!因此,你的定義是一個不同的功能。

+0

謝謝rodrigo - demangler很酷!我很感激你幫助我 – 2013-03-14 23:14:42

3

由於接頭告訴你,這個問題是與rand_neighbor()功能。你爲它提供一個聲明(如果你沒有,你會得到一個編譯錯誤,而不是鏈接錯誤),但你卻沒有提供定義

+0

嗯,對不起,截斷了帖子。我確實有一個rand_neighbor的定義。更新以包括它 - 但問題仍然存在? – 2013-03-14 22:55:25

+0

@TylerSeymour:好的,請更新帖子。你最有可能有一個不符合聲明的定義(不同的簽名) – 2013-03-14 22:56:32

相關問題