gpt4 book ai didi

c++ - C++ 中的链接错误

转载 作者:行者123 更新时间:2023-11-28 03:49:25 24 4
gpt4 key购买 nike

我只是对我一直致力于在 OpenGL 中渲染场景的项目进行最后的润色——我的一些项目基于我为 Camera 类编写的一些旧代码(因为我不想必须重新算出数学!),但是我之前将 Camera 类作为 main.cpp 的一部分包含在内,为了可重用性/清晰度,我想将它移动到它自己的单独的 .h/.cpp 文件中/一般良好做法。

我还用我编写的 Mouse 类替换了一个基本的 Struct 来保存鼠标的 x 和 y 位置。

我更改了 Windows 消息处理程序中的一些代码,以便在释放鼠标左键时更新相机 - 但是我收到一个奇怪的链接错误 -

1>main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Camera::moveCamera(int,int,int,int)" (?moveCamera@Camera@@QAEXHHHH@Z)

Windows 消息处理程序中的代码是 -

    case WM_LBUTTONUP:
Mouse.SetPos(lParam);
x_mouse_end = Mouse.GetXPos();
y_mouse_end = Mouse.GetYPos();
Camera.moveCamera(x_mouse_start, y_mouse_start, x_mouse_end, y_mouse_end);
SetCamera();
break;

我传递给 Camera.moveCamera() 的参数是整数,因为它们应该是整数。

moveCamera()函数如下——

//Moves the camera based on a user dragging the mouse 
inline void Camera::moveCamera(int old_x, int old_y, int new_x, int new_y)
{
//To store the differences between the old and new mouse positions
int x_difference, y_difference;

//If the mouse was dragged to the right, move the camera right
if(new_x > old_x)
{
x_difference = new_x - old_x;
x_difference = x_difference / 25;

if(yaw > 350)
{
yaw = 0;
}
else
{
yaw = yaw + x_difference;
}
}

//If the mouse was dragged to the left, move the camera left
if(new_x < old_x)
{
x_difference = old_x - new_x;
x_difference = x_difference / 25;

if(yaw < 10)
{
yaw = 360;
}
else
{
yaw = yaw - x_difference;
}
}

//If the mouse was dragged down, move the camera down
if(new_y < old_y)
{
y_difference = new_y - old_y;
y_difference = y_difference / 20;

if(pitch < 10)
{
pitch = 360;
}
else
{
pitch = pitch - y_difference;
}
}

//If the mouse was dragged up, move the camera up
if(new_y > old_y)
{
y_difference = old_y - new_y;
y_difference = y_difference / 20;
if(pitch > 350)
{
pitch = 0;
}
else
{
pitch = pitch + y_difference;
}
}

//Update the camera position based on the new Yaw, Pitch and Roll
cameraUpdate();

}

“camera.h”和“mouse.h”一样包含在内,并且两个类的实例都已设置 -

Mouse Mouse;
Camera Camera;

我不知道可能缺少什么。

如果您想了解更多信息,请告诉我。

最佳答案

也许您将 moveCamera() 的定义包含在带有“inline”关键字的 .cpp 文件中。这可能被解释为该方法在定义它的 .cpp 中是本地的。尝试删除 inline

关于c++ - C++ 中的链接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6057668/

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