6“错误LNK2019:未解析的外部符号”

时间:2013-01-30 17:17:34

标签: c++ linker-errors game-engine sfml unresolved-external

我有6个未解决的外部因素。我知道这意味着什么,但我不知道如何解决它。

Collision.cpp

#include "Collision.h"

void Collision::Collide(Entity &entity1, Entity &entity2)
{
    if(entity1.getX() + entity1.getWidth() > entity2.getX() ||
        entity1.getX() < entity2.getX() + entity2.getWidth() ||
        entity1.getY() + entity1.getHeight() > entity2.getY() ||
        entity1.getY() < entity2.getY() + entity2.getHeight())
    {
        entity1.setX(entity1.getX());
        entity1.setY(entity1.getY());

    }
}

Collision.h

#ifndef COLLISION_H
#define COLLISION_H

#include "Map.h"
#include "Animation.h"
#include "Entity.h"

class Collision
{
public:
    void Collide(Entity &entity1, Entity &entity2);
protected:
    Map map;
};

#endif

调用碰撞的地方

collision.Collide(player, enemy);

Entity.h

#ifndef Entity_H
#define Entity_H

#include<SFML/Graphics.hpp>
#include"Animation.h"
#include"Camera.h"

class Entity
{
    public:

        void Initialize();
        void LoadContent();
        void Update(sf::RenderWindow &Window);
        void Draw(sf::RenderWindow &window);
        void setX(float newX);
        void setY(float newY);
        int getHeight();
        int getWidth();
        float getX();
        float getY();
    private:
        Camera camera;
        float x, y;
        int currentFrameX, currentFrameY;
        sf::Clock clock;
};

#endif // Entity_H

未解决的外部

1>Collision.obj : error LNK2019: unresolved external symbol "public: void __thiscall Entity::setX(float)" (?setX@Entity@@QAEXM@Z) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide@Collision@@QAEXAAVEntity@@0@Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: void __thiscall Entity::setY(float)" (?setY@Entity@@QAEXM@Z) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide@Collision@@QAEXAAVEntity@@0@Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: int __thiscall Entity::getHeight(void)" (?getHeight@Entity@@QAEHXZ) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide@Collision@@QAEXAAVEntity@@0@Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: int __thiscall Entity::getWidth(void)" (?getWidth@Entity@@QAEHXZ) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide@Collision@@QAEXAAVEntity@@0@Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: float __thiscall Entity::getX(void)" (?getX@Entity@@QAEMXZ) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide@Collision@@QAEXAAVEntity@@0@Z)
1>Collision.obj : error LNK2019: unresolved external symbol "public: float __thiscall Entity::getY(void)" (?getY@Entity@@QAEMXZ) referenced in function "public: void __thiscall Collision::Collide(class Entity &,class Entity &)" (?Collide@Collision@@QAEXAAVEntity@@0@Z)

我认为在Player / Enemy课程中没有正确重载Entity getX()等是一个问题。

1 个答案:

答案 0 :(得分:1)

事实证明Entity.cpp尚未包含在我的项目中。

谢谢克里斯和西蒙克!

相关问题