我还是一种新的C++,不知道为什么我在尝试在另一个类中调用这些函数时遇到这些链接器错误。C++链接器错误LNK2019
的错误是:
error LNK2019: unresolved external symbol "public: float __thiscall Star::getMass(void)" ([email protected]@@QAEMXZ) referenced in function "public: void __thiscall Projectile::Update(class Star * const,int)" ([email protected]@@[email protected]@[email protected])
error LNK2019: unresolved external symbol "public: float __thiscall Star::getX(void)" ([email protected]@@QAEMXZ) referenced in function "public: void __thiscall Projectile::Update(class Star * const,int)" ([email protected]@@[email protected]@[email protected])
error LNK2019: unresolved external symbol "public: float __thiscall Star::getY(void)" ([email protected]@@QAEMXZ) referenced in function "public: void __thiscall Projectile::Update(class Star * const,int)" ([email protected]@@[email protected]@[email protected])
Projectile.cpp:
#include <hge.h>
#include "Projectile.h"
#include "Physics.h"
#include "Star.h"
#include <math.h>
Projectile::Projectile(float xV, float yV, float x, float y, float m, HTEXTURE tex)
{
xVel = xV;
yVel = yV;
xPos = x;
yPos = y;
mass = m;
quad.tex = tex;
}
void Projectile::Update(Star stars[], int length)
{
for(int i = 0; i<length; ++i)
{
float force = Physics::calcGravityForce(mass, stars[i].getMass(), Physics::calcDist(xPos, yPos, stars[i].getX(), stars[i].getY()));
Accelerate(force, stars[i].getX() - xPos, stars[i].getY() - yPos);
}
}
void Projectile::Accelerate(float force, float x, float y)
{
float c = sqrt((x * x) + (y * y));
xVel += x/c;
yVel += y/c;
}
星在Star.h定义在这里:
#ifndef STAR_H
#define STAR_H
#include <hge.h>
class Star
{
private:
float mass, radius, x, y;
hgeQuad quad;
public:
Star(float m, float r, float X, float Y, HTEXTURE);
float getMass();
float getRadius();
float getX();
float getY();
Star() {}
};
#endif
哇哦,我笨我完全忘了定义这些。对不起,感谢您的帮助! – Nate
@如果此答案回答了您的问题,请不要忘记将其标记为答案,方法是单击左侧的复选标记。 –