0

我无法弄清楚我的错误在哪里。我收到消息:

Error   21  error LNK2019: unresolved external symbol "public: __thiscall ParticleAnchoredSpring::ParticleAnchoredSpring(class Vector3 *,float,float)" (??0ParticleAnchoredSpring@@QAE@PAVVector3@@MM@Z) referenced in function "public: void __thiscall MyGameWorld::Initialize(void)" (?Initialize@MyGameWorld@@QAEXXZ)   C:\Users\Foo Nuts\Dropbox\GSP321_DavidJohnson\GSP321_Johnson_HM2\iLab2\MyGameWorld.obj

函数声明:

ParticleForceRegistry registry;
ParticleAnchoredSpring spring(&Vector3(10, 3, 10), 10, 10);

registry.add(WMI->getListPtr()[0], &spring);

类定义:

class ParticleAnchoredSpring : public ParticleForceGenerator
{
protected:
    Vector3 *anchor;
    real springConstant, restLength;
public:
     ParticleAnchoredSpring(Vector3 *anchor, real springConstant, real restLength);
     virtual void updateForce(Particle *particle, real time);
};

构造函数声明:

void ParticleAnchoredSpring::updateForce(Particle *particle, real time)
{
Vector3 force;
particle->getPosition();
force -= *anchor;

real magnitude = force.magnitude();
magnitude = (restLength - magnitude) * springConstant ;
magnitude *= springConstant;

force.normalize();
force *= -magnitude;
particle->addForce(force);
}
4

1 回答 1

0

You haven't implemented the constructor. You only declared it. Add:

ParticleAnchoredSpring::ParticleAnchoredSpring(Vector3 *_anchor, real _springConstant, real _restLength) 
: anchor(_anchor), springConstant(_springConstant), restLength(_restLength)
{
}

to your implementation file.

I'll assume real is defined as float.

于 2012-08-01T04:12:49.857 回答