c++ - 尝试实现抽象类时出现 undefined reference 错误

标签 c++ compiler-errors linker

我有一个抽象类,它是一个接口(interface):

//hpp
#ifndef IMOVABLE_HPP_INCLUDED
#define IMOVABLE_HPP_INCLUDED

#include "StaticMovementPath.hpp"

class IMovable{
protected:
    StaticMovementPath *staticMovementPath;
public:
    IMovable();
    virtual setStaticMovementPath(StaticMovementPath *staticmovementPath) = 0;
};

#endif // IMOVABLE_HPP_INCLUDED

//cpp
#include "IMovable.hpp"

#include "StaticMovementPath.hpp"

IMovable::IMovable()
{
    staticMovementPath = new StaticMovementPath();
}



//hpp
#ifndef STATICMOVEMENTPATH_HPP_INCLUDED
#define STATICMOVEMENTPATH_HPP_INCLUDED

class StaticMovementPath{
public:
    StaticMovementPath();
};

#endif // STATICMOVEMENTPATH_HPP_INCLUDED

//cpp
#include "StaticMovementPath.hpp"

StaticMovementPath::StaticMovementPath(){
};




//hpp
#ifndef CAMERA_HPP
#define CAMERA_HPP

#include "IMovable.hpp"

class Camera: public IMovable{
public:
    Camera();
};

#endif // CAMERA_HPP

//cpp
#include "Camera.hpp"

#include "IMovable.cpp"

Camera::Camera() : IMovable(){
}

编译这个会抛出:
||=== Build: Debug in mapEditor (compiler: GNU GCC Compiler) ===|
obj\Debug\src\Camera.o||In function `ZN8IMovableC2Ev':|
...\src\IMovable.cpp|8|undefined reference to `StaticMovementPath::StaticMovementPath()'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

如果我没有定义构造函数(所以调用了默认构造函数),我不会出错。但是,对于具有一个或多个参数的构造函数,我会遇到同样的错误。

我该如何进行这项工作?

我知道大部分代码似乎毫无意义,但我尽可能地对其进行了精简。 (更多)完整代码引发了相同的错误。

最佳答案

StaticMovementPath.cpp 既不是调试目标,也不是发布目标,所以它根本没有编译。

关于c++ - 尝试实现抽象类时出现 undefined reference 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40002790/

相关文章:

c++ - 如何使用 tntdb 类更新 Sqlite 数据库中的字符串值

module - OCaml 中的未绑定(bind)模块

c++ - makefile 为不同的体系结构设置不同的链接器标志

gcc - 交叉编译时缺少 crt1 和 crti

c++ - 努力将在一个函数中创建的数组传递给排序函数

c++ - C++ 中集合/容器的接口(interface)/父类(super class)

没有类的 C++ 用户定义转换运算符?

haskell - Haskell在输入 `<-'上解析错误

ios - Xcode 错误 : Semantic Issue, 在对象类型 'className' 上找不到属性 'GKEntity *'

c++ - 外部符号的可见性和可移植性