我试图从抽象类继承,但收到以下错误:
在文件中包含从 /usr/include/c /5/vector: 64:0,从 /usr/include/boost/format.hpp:17,从 /usr/include/boost/math/policies/error_handling.hpp:31,从 /usr/include/boost/math/special_functions/round.hpp:14,从 /opt/ros/kinetic/include/ros/time.h:58,从 /opt/ros/kinetic/include/ros/ros.h:38,从 /home/gil/catkin_ws/src/manager/include/Tasks/Task.h:4,从 /home/gil/catkin_ws/src/manager/src/Tasks/Task.cpp:1: /usr/include/c /5/bits/stl_vector.h:713:7:错误:无效的抽象参数类型'manager__xTask'resize(size_type__new_size,value_type__x= /usr/include/c())
--
/home/gil/catkin_ws/src/manager/include/Tasks/Task.h: 11:16:注意:
虚拟无效管理器catkin_ws任务stl_vectorxecute()虚拟无效执行()=0;^包含在文件中 /usr/include/c /5/vector:64:0, /usr/include/boost/format.hpp:17, /usr/include/boost/math/policies/error_handling.hpp:31, /usr/include/boost/math/special_functions/round.hpp:14, /opt/ros/kinetic/include/ros/time.h:58, /opt/ros/kinetic/include/ros/ros.h:38, /home/gil/catkin_ws/src/manager/include/Tasks/Task.h:4, /home/gil/catkin_ws/src/manager/include/Tasks/RootTask.h:10, /home/gil/catkin_ws/src/manager/src/Tasks/RootTask.cpp:8 /usr/include/c /5/bits/stl_vector.h:713:7:错误:无效抽象参数类型'manager::Task'resize(size_type__new_sizevalue_type__x=value_type())
--
Manager/CMakeFiles/manager. dir/build.make:110:目标'manager/CMakeFiles/manager.dir/src/T的任务/Task.cpp.o'的配方失败make[2]:*[manager/CMakeFiles/manager.dir/src/的任务/的任务.cpp.o]错误1 make[2]:*等待未完成的工作……manager/CMakeFiles/manager.dir/build.make:158:目标'manager/CMakeFiles/manager.dir/src/的任务/RootTask.cpp.o'的配方失败make[2]: *** [manager/CMakeFiles/manager.dir/src/的任务/RootTask.cpp.o]错误1包含在文件中从 /usr/include/c /5/vector:64:0,从 /usr/include/boost/format.hpp:17,从 /usr/include/boost/math/policies/error_handling.hpp:31,从 /usr/include/boost/math/special_functions/round.hpp:14,从 /opt/ros/kinetic/include/ros/time.h:58,从 /opt/ros/kinetic/include/ros/ros.h:38,从 /home/GIL/catkin_ws/src/manager/src/indoor_mission_action_server. cpp:9: /usr/include/c /5/bits/stl_vector.h:713:7:错误:无效的抽象参数类型'manager::Task'resize(size_type__new_size,value_type__x=value_type())
不知道我错过了什么…这是我的H和CPP文件:
RootTask. cpp
#include "Tasks/RootTask.h"
namespace manager {
RootTask::RootTask(std::string name) {
mTaskName = name;
}
RootTask::~RootTask() {}
RootTask::RootTask() {}
void RootTask::Execute() {}
void RootTask::setTaskSeqByName() {}
std::string RootTask::GetTaskName() {
return mTaskName;
}
}
RootTask. h
#include "Tasks/Task.h"
namespace manager {
class RootTask: public Task {
public:
RootTask();
RootTask(std::string name);~RootTask();
void Execute();
void setTaskSeqByName();
std::string GetTaskName();
};
}
任务. cpp
#include "Tasks/Task.h"
#include < iostream >
namespace manager {
void Task::Stop() {}
void Task::Pause() {}
void Task::OnError() {}
std::string Task::GetTaskName() {}
void Task::setTaskSeqByName() {}
}
任务h
#pragma once
#include < iostream >
#include "ros/ros.h"
namespace manager {
class Task {
public:
virtual void Execute() = 0;
virtual void setTaskSeqByName();
virtual void Stop();
virtual void Pause();
virtual void OnError();
virtual std::string GetTaskName();
protected:
std::string mTaskName;
std::vector < Task > mTaskSequence;
};
}
谢谢你的帮助。
在Task
中,您有一个成员
std::vector < Task > mTaskSequence;
您不能拥有它,因为Task
是一个抽象类,您不能创建它的实例。您需要使用像这样的指针类型
std::vector<std::unique_ptr<Task>> mTaskSequence;
@NathanOliver的回答指出了如何修复编译器错误。
我想指出,让Task
包含指向其他Task
的指针列表似乎是一个可能的设计缺陷。
您可能需要考虑将其移动到处理Task
s序列的更高级别的类。