gpt4 book ai didi

c++ - 将值传递给函数

转载 作者:行者123 更新时间:2023-11-28 03:43:57 26 4
gpt4 key购买 nike

不用再看了,我发现了错误,但我不能在八小时前回答自己,因为我有几个要点。

我想将指针(它在 Window 类中声明并在其构造函数中赋值)值引用传递给在类函数“Draw”中声明的函数“fillBorderVertexes”,但编译器向我抛出此错误:

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);
}

最佳答案

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

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

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

关于c++ - 将值传递给函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8272942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com