C++中的链接错误

Linking error in C++

本文关键字:错误 链接 C++      更新时间:2023-10-16

我只是在对我一直在做的一个在OpenGL中渲染场景的项目进行最后的润色 - 我基于我为相机类编写的一些旧代码(因为我不想重新计算数学!),但是我之前将相机类作为main的一部分.cpp 我想将其移动到它自己的单独 .h/.cpp 文件中,以便可重用性/清晰度/一般良好实践。

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

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

1>main.obj : 错误 LNK2001: 未解决 外部符号"公共:无效 __thiscall 相机::移动相机(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;

我不知道可能缺少什么。

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

也许您在带有" inline"关键字的.cpp文件中包含了moveCamera()的定义。这可以解释为此方法是定义它的.cpp的本地方法。尝试删除inline

相关文章: