我還是一種新的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
@如果此答案回答了您的問題,請不要忘記將其標記爲答案,方法是單擊左側的複選標記。 –