gpt4 book ai didi

c++ - 为什么我的虚拟功能不起作用?

转载 作者:行者123 更新时间:2023-11-28 08:31:29 24 4
gpt4 key购买 nike

我有一个名为 camera 的抽象类,PointCamera 将其用作其父类(super class)。出于某种原因,其中一个虚函数在调试器中抛出错误,并告诉我它正在尝试执行 0x00000000。仅当所讨论的函数是抽象类中声明的最后一个函数时才会发生这种情况。如果我切换声明顺序,那么新的 last 函数将出于同样的原因不起作用。为什么会这样?

class Camera
{
public:
//Default constructor
Camera();

//Assignment operator
virtual Camera* clone() = 0;

//Get a ray
virtual void KeyCamera() = 0;
virtual void GetRay(float x, float y, Ray* out) = 0;
};

class PointCamera: Camera
{
private:
//Camera location, target, and direction
Vector loc, dir, tar, up;
//Orthonormal vectors
Vector u, v, w;
//Virtual plane size
float plane_width, plane_height;
int width, height;
//Distance from the camera point to the virtual plane
float lens_distance;
//Pixel size
float pixelSizex, pixelSizey;

public:
//Default constructor
PointCamera();
//Constructors
PointCamera(Vector& iloc, Vector& itar);
PointCamera(Vector& iloc, Vector& itar, Vector& idir);

//Destructor
~PointCamera();

//Modifiers
void SetDirection(Vector& idir);
void SetUp(Vector& iup);
void SetTarget(Vector& itar);
void SetLocation(Vector& iloc);
void SetPlane(int iheight, int iwidth, float iplane_width = -1.0f, float iplane_height = -1.0f);
void SetLensDistance(float ilens_distance);

//Implememented method
virtual void GetRay(float x, float y, Ray* out);
virtual void SetupRay(Ray* out);

//Compute orthonormal vectors
virtual void KeyCamera();
};

最佳答案

Ok I just re-compiled everything and it worked. I don't know what went wrong. Thanks for your suggestions.

检查您的依赖项。我敢打赌应该取决于头文件的东西不是。当您进行干净构建时,依赖于该头文件的源代码文件已更新。

关于c++ - 为什么我的虚拟功能不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1806687/

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