2011-11-25 58 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