将值传递给函数

时间:2011-11-25 18:20:43

标签: c++ visual-studio-2008

无需再看了,我发现了错误,但我无法在八小时之前回答自己,因为我必须得到几分。

我想传递一个指针(它在一个Window类中声明并在其构造函数中被赋值)对函数" fillBorderVertexes"的值引用。这是在类函数内声明的#34; Draw"但编译器抛出了这个错误:

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)" (?fillBorderVertexes@@YAXPAVTransparentMaze@@PAV?$vector@V?$vector@MV?$allocator@M@std@@@std@@V?$allocator@V?$vector@MV?$allocator@M@std@@@std@@@2@@std@@MMH@Z) referenced in function "public: virtual void __thiscall Window::draw(void)" (?draw@Window@@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);
}

2 个答案:

答案 0 :(得分:1)

是的,我相信编译器无法找到函数fillBorderVertexes的定义。 .cpp文件是否存在于项目中的实现?

答案 1 :(得分:1)

检查fillBorderVertexes()函数的定义是否与声明完全匹配。例如,如果以下是定义:

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

链接器会产生错误,因为第一个参数在声明中定义为TransparentMaze*,但在定义中定义为TransparentMaze