未定义对派生类的引用

时间:2019-06-19 02:26:45

标签: c++ inheritance

模拟后编辑 也许我的析构函数有问题。

我使用“ new”的唯一步骤是
    “ pcl :: PointCloud :: Ptr cloud_inbox(新pcl :: PointCloud); ” 创建pcl数据。

CoordinateTran.h就像这样:

#ifndef COORDINATETRAN_H
#define COORDINATETRAN_H
#include...h file
namespace huskybot_arm
{

  class CoordinateTran
  {

    public:
    explicit CoordinateTran(ros::NodeHandle nh);
    virtual ~CoordinateTran()=default;

    protected:

    ...

  };


  class CoordinateTran3D :public CoordinateTran
  {
    public:
    explicit CoordinateTran3D(ros::NodeHandle nh);  
    ~CoordinateTran3D()=default;
    private:
    ...
  };
}
#endif

main.cpp就是这样

#include "CoordinateTran.h"
int main(int argc, char **argv) 
{

  ros::init(argc, argv, "coord_tran");
  ros::NodeHandle nh("~"); 
  huskybot_arm::CoordinateTran3D coordTran3D(nh);
  ros::spin(); 
  return 0;
}

coordinateTran.cpp就是这样

#include "ros/ros.h"
#include "CoordinateTran.h"
namespace huskybot_arm
{ 

    CoordinateTran::CoordinateTran(ros::NodeHandle nh)
    :get_target(0)
    {
     ...
     ...
     ...
    }

        ...functions

}

coordinateTran3D.cpp就是这样

#include "ros/ros.h"
#include "CoordinateTran.h"

namespace huskybot_arm
{ 

     CoordinateTran3D::CoordinateTran3D(ros::NodeHandle nh):CoordinateTran(nh),viewer("cloud in box"){
      pcl_pub = nh.advertise<sensor_msgs::PointCloud2> ("pcl_output", 100);
    }


    void CoordinateTran3D::pointCouldCallback( const sensor_msgs::PointCloud2::ConstPtr &point_cloud_msg) 
    {


    pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_inbox (new pcl::PointCloud<pcl::PointXYZ>);
    cloud_inbox->clear();
    sensor_msgs::PointCloud2 cloud_inbox_msgs;

    if (get_target == 1)
    {
        pcl::PointCloud<pcl::PointXYZ> point_pcl;
        pcl::fromROSMsg(*point_cloud_msg, point_pcl);
        //pcl::PointCloud<pcl::PointXYZ> cloud_inbox;

        if (point_pcl.isOrganized ())
        {

            cloud_inbox->width =x_max-x_min+1;
            cloud_inbox->height =y_max - y_min +1;
            std::cout << "cloud_inbox.width "<<cloud_inbox->width << "cloud_inbox.height  " << cloud_inbox->height <<std::endl;
            cloud_inbox->points.resize (cloud_inbox->width * cloud_inbox->height);
            std::cout << "new cloud" <<std::endl;
            for (int i=0; i< cloud_inbox->width&&i+x_min<640; ++i)
            {
               for (int j=0; j< cloud_inbox->height&&j+y_min<480; ++j)
               {
                   cloud_inbox->at(i,j).x =point_pcl.at(x_min+i,y_min+j).x;
                   cloud_inbox->at(i,j).y =point_pcl.at(x_min+i,y_min+j).y;
                   cloud_inbox->at(i,j).z =point_pcl.at(x_min+i,y_min+j).z;

               }
            }


            pcl::PointXYZ pt = point_pcl.at(u,v);
            camera_x = pt.x;
            camera_y = pt.y;
            camera_z = pt.z;
            std::cout << " coordnate get: " << " camera_x " <<camera_x <<" camera_y " <<camera_y <<" camera_z " <<camera_z <<std::endl;


        }
        else
        std::cout << " the pointcloud is not organized " << std::endl;
        //std::cout << "\033[2J\033[1;1H";     // clear terminal
    }
    viewer.showCloud(cloud_inbox);
    pcl::toROSMsg(*cloud_inbox, cloud_inbox_msgs);
    cloud_inbox_msgs.header.frame_id = "camera_color_optical_frame";
    pcl_pub.publish(cloud_inbox_msgs);

    }

}

它显示

/home/qiuyilin/catkin_ws/src/Huskybot_arm/coord_tran/coord_tran/src/coord_tran_node.cpp:16:对huskybot_arm::CoordinateTran3D::CoordinateTran3D(ros::NodeHandle)' CMakeFiles/coord_tran_node.dir/src/coord_tran_node.cpp.o: In function huskybot_arm :: CoordinateTran3D :: ~~ CoordinateTran3D()'的未定义引用:     /home/qiuyilin/catkin_ws/src/Huskybot_arm/coord_tran/coord_tran/include/CoordinateTran.h:91:对huskybot_arm :: CoordinateTran3D的vtable的未定义引用

1 个答案:

答案 0 :(得分:3)

您的pointCouldCallback声明错误是因为override放在错误的位置;它放在参数列表之后,如下所示:

void pointCouldCallback( const sensor_msgs::PointCloud2::ConstPtr &point_cloud_msg) override;
//                                                                                  ^^^^^^^^

您的CoordinateTran3D错误是因为,即使构造函数没有做任何事情,它仍然需要一个body。

explicit CoordinateTran3D(ros::NodeHandle nh):CoordinateTran(nh) {};  
//                               can just be inlined like this   ^^