C++ pure virtual error
我正在尝试从抽象类继承,但出现以下错误:
In file included from /usr/include/c++/5/vector:64:0,
from /usr/include/boost/format.hpp:17,
from /usr/include/boost/math/policies/error_handling.hpp:31,
from /usr/include/boost/math/special_functions/round.hpp:14,
from /opt/ros/kinetic/include/ros/time.h:58,
from /opt/ros/kinetic/include/ros/ros.h:38,
from /home/gil/catkin_ws/src/manager/include/Tasks/Task.h:4,
from /home/gil/catkin_ws/src/manager/src/Tasks/Task.cpp:1:
/usr/include/c++/5/bits/stl_vector.h:713:7: error: invalid abstract
parameter type a€?manager::Taska€?
resize(size_type __new_size, value_type __x = value_type())
—
/home/gil/catkin_ws/src/manager/include/Tasks/Task.h:11:16: note:
virtual void manager::Task::Execute() virtual void Execute() = 0;
^ In file included from /usr/include/c++/5/vector:64:0,
from /usr/include/boost/format.hpp:17,
from /usr/include/boost/math/policies/error_handling.hpp:31,
from /usr/include/boost/math/special_functions/round.hpp:14,
from /opt/ros/kinetic/include/ros/time.h:58,
from /opt/ros/kinetic/include/ros/ros.h:38,
from /home/gil/catkin_ws/src/manager/include/Tasks/Task.h:4,
from /home/gil/catkin_ws/src/manager/include/Tasks/RootTask.h:10,
from /home/gil/catkin_ws/src/manager/src/Tasks/RootTask.cpp:8:
/usr/include/c++/5/bits/stl_vector.h:713:7: error: invalid abstract
parameter type a€?manager::Taska€?
resize(size_type __new_size, value_type __x = value_type())
—
manager/CMakeFiles/manager.dir/build.make:110: recipe for target
‘manager/CMakeFiles/manager.dir/src/Tasks/Task.cpp.o’ failed make[2]:
* [manager/CMakeFiles/manager.dir/src/Tasks/Task.cpp.o] Error 1 make[2]: * Waiting for unfinished jobs….
manager/CMakeFiles/manager.dir/build.make:158: recipe for target
‘manager/CMakeFiles/manager.dir/src/Tasks/RootTask.cpp.o’ failed
make[2]: *** [manager/CMakeFiles/manager.dir/src/Tasks/RootTask.cpp.o]
Error 1 In file included from /usr/include/c++/5/vector:64:0,
from /usr/include/boost/format.hpp:17,
from /usr/include/boost/math/policies/error_handling.hpp:31,
from /usr/include/boost/math/special_functions/round.hpp:14,
from /opt/ros/kinetic/include/ros/time.h:58,
from /opt/ros/kinetic/include/ros/ros.h:38,
from /home/gil/catkin_ws/src/manager/src/indoor_mission_action_server.cpp:9:
/usr/include/c++/5/bits/stl_vector.h:713:7: error: invalid abstract
parameter type a€?manager::Taska€?
resize(size_type __new_size, value_type __x = value_type())
不知道我错过了什么……
这是我的 H 和 CPP 文件:
RootTask.cpp
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include"Tasks/RootTask.h" namespace manager { RootTask::RootTask(std::string name) { mTaskName = name; } RootTask::~RootTask() {} RootTask::RootTask() {} void RootTask::Execute() {} void RootTask::setTaskSeqByName() {} |
RootTask.h
1
2 3 4 5 6 7 8 9 10 11 12 13 |
#include"Tasks/Task.h" namespace manager { class RootTask: public Task { public: RootTask(); void Execute(); |
任务.cpp
1
2 3 4 5 6 7 8 9 10 |
#include"Tasks/Task.h" #include < iostream > namespace manager { |
任务.h
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#pragma once
#include < iostream > namespace manager { protected: |
感谢您的帮助。
在
1
|
std::vector < Task > mTaskSequence;
|
你不能拥有它,因为
这样的指针类型
1
|
std::vector<std::unique_ptr<Task>> mTaskSequence;
|
@NathanOliver 的回答指出了如何修复编译器错误。
我想指出,让
您可能需要考虑将其移至处理
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/268958.html