我在这里有此代码:
Main.cpp
#include "AStarPlanner.h"
#include <costmap_2d/costmap_2d.h>
int main(int argc, char** argv)
{
AStarPlanner planner = AStarPlanner(10,10,&costmap);
}
和我的类(class):
AStarPlanner.h
class AStarPlanner {
public:
AStarPlanner(int width, int height, const costmap_2d::Costmap2D* costmap);
virtual ~AStarPlanner();
AStarPlanner.cpp
#include "AStarPlanner.h"
using namespace std;
AStarPlanner::AStarPlanner(int width, int height, const costmap_2d::Costmap2D* costmap)
{
ROS_INFO("Planner Konstruktor");
width_ = width;
height_ = height;
costmap_ = costmap;
}
我看不到我有任何错误。该函数已定义,并且我的main.cpp知道该类。
CMakeList
cmake_minimum_required(VERSION 2.4.6)
include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
rosbuild_init()
#set the default path for built executables to the "bin" directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
#set the default path for built libraries to the "lib" directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
rosbuild_add_library (robot_mover src/AStarPlanner.cpp )
rosbuild_add_executable(robot_mover src/main.cpp)
但是我得到这个错误:
未定义对
vtable for AStarPlanner'**** undefined reference to
的引用AStarPlanner::〜AStarPlanner()' 最佳答案
您未能为AStarPlanner
定义析构函数。您可以这样将其添加到AStarPlanner.cpp中:
AStarPlanner::~AStarPlanner()
{
}
考虑this advice。