2011-11-25 86 views
0

不需要再看,我發現了錯誤,但是在八個小時之前我不能回答自己,因爲我得幾分。把價值傳遞給一個函數

我想要在類函數「Draw」中聲明的函數「fillBorderVertexes」傳遞一個指針(它在Window類中聲明並在其構造函數中賦值),但編譯器會拋出此錯誤:

1>window.obj : error LNK2019: unresolved external symbol "void __cdecl fillBorderVertexes(class TransparentMaze *,class std::vector<class std::vector<float,class std::allocator<float> >,class std::allocator<class std::vector<float,class std::allocator<float> > > > *,float,float,int)" ([email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected][email protected]@[email protected]@@[email protected]@@[email protected]@[email protected]@[email protected]) referenced in function "public: virtual void __thiscall Window::draw(void)" ([email protected]@@UAEXXZ) 
1>C:\Users\Asus\Desktop\VC++\PacMan\Debug\PacMan.exe : fatal error LNK1120: 1 unresolved externals 

它是否與這樣的事情有關,在這個函數內部的指針值或其某些部分是不可見的?

void Window::draw() { 
::glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer 
::glLoadIdentity(); 

void fillBorderVertexes(TransparentMaze*, vector<vector<GLfloat>>*, GLfloat, GLfloat, int); 
void fillMazeVertexes(vector<vector<GLfloat>>*, Room*, GLfloat, GLfloat, int); 
void drawMaze(vector<vector<GLfloat>>*, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat); 

static vector<vector<GLfloat>> borderVertexes; 
static vector<vector<GLfloat>> mazeVertexes; 
static bool done = false; 

std::map<Point, Room*, compare>::iterator it = maze->getMaze().begin(); 

GLfloat x = ((GLfloat)it->first.getX() - 0.5f) * (room + border) - ((GLfloat)maze->getWidth()/2.0f * (room + border)); 
GLfloat y = ((GLfloat)maze->getHeight()/2.0f * (room + border)) - ((GLfloat)it->first.getY() - 0.5f) * (room + border); 

if (!done) { 
    // The problem is in this function with the first variable 
    fillBorderVertexes(&*maze, &borderVertexes, room, border, ANGULAR_CORNERS); 

    fillMazeVertexes(&mazeVertexes, &*it->second, room, border, ANGULAR_CORNERS); 
    done = true; 
} 

drawMaze(&mazeVertexes, x, y, imageW, imageH, imageD); 

::SwapBuffers(hdc); 
} 
+1

這不是一個編譯器錯誤,它是一個鏈接器錯誤。 –

+0

爲什麼'&*迷宮'而不僅僅是'迷宮'? –

回答

1

檢查fillBorderVertexes()函數的定義是否與聲明完全匹配。例如,如果以下是定義:

void fillBorderVertexes(TransparentMaze, vector<vector<GLfloat>>*, GLfloat, GLfloat, int) 
{ 
} 

接頭會產生它是作爲第一個參數定義爲在聲明一個TransparentMaze*但如在定義TransparentMaze的誤差。

+0

剛注意到你已經自己解決了這個問題...... – hmjd

+0

是的,但你是對的。 – Jaak

1

是的,我相信編譯器無法找到函數fillBorderVertexes的定義。項目中實現存在的.cpp文件是否存在?

+0

函數原型在「draw」函數的開頭,實現在函數之後,函數本身現在不做任何事情,因爲我無法傳遞第一個參數「&* maze」。 – Jaak