我有一个抽象类,它应该是一个接口:
//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)) ===|
如果我没有定义构造函数(因此调用默认构造函数),我没有错误。但是,对于具有一个或多个参数的构造函数,我得到了相同的错误。
我如何使这项工作?
我知道大部分代码似乎毫无意义,但我尽可能地删除它。使用(更多)完整代码抛出相同的错误。
答案 0 :(得分:0)
StaticMovementPath.cpp没有针对调试或发布的目标,所以它根本就没有编译。