C++ 我如何知道是什么导致不完整类型因错误而不完整:指向不完整类型的指针上的算术

C++ 我如何知道是什么导致不完整类型因错误而不完整:指向不完整类型的指针上的算术,c++,struct,instance,forward-declaration,point-cloud-library,C++,Struct,Instance,Forward Declaration,Point Cloud Library,我尝试定义自己的PointT类型,在单个点中为我提供XYZRGBA和强度值。我试图遵循本文在点云库网站上列出的约定: PointXYZRGBAI的实现在我的一个类的.CPP文件中,但我在其他头文件包含的头文件中转发声明它。实现在LidarFile.cpp中: struct PointXYZRGBAI{ PCL_ADD_POINT4D; union{ struct{ float intensity; uint32_t rgba; }; flo

我尝试定义自己的PointT类型,在单个点中为我提供XYZRGBA和强度值。我试图遵循本文在点云库网站上列出的约定:

PointXYZRGBAI的实现在我的一个类的.CPP文件中,但我在其他头文件包含的头文件中转发声明它。实现在LidarFile.cpp中:

struct PointXYZRGBAI{
  PCL_ADD_POINT4D;
  union{
    struct{
      float intensity;
      uint32_t rgba;
    };
    float data_c[4];
  };
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
} EIGEN_ALIGN_16;

POINT_CLOUD_REGISTER_POINT_STRUCT(PointXYZRGBAI,
                                  (float, x, x)
                                  (float, y, y)
                                  (float, z, z)
                                  (float, intensity, intensity)
                                  (uint32_t, rgba, rgba)
)

inline std::ostream& operator << (std::ostream& os, const PointXYZRGBAI& p){
  os << "(" << p.x << ", " << p.y << ", " << p.z << " - " << p.intensity << " - " << p.rgba << ")";
  return (os);
}
struct PointXYZRGBAI{
PCL_添加_点4d;
联合{
结构{
漂浮强度;
uint32_t rgba;
};
浮动数据_c[4];
};
特征值\u使\u对齐\u运算符\u新
}本征对准16;
点云寄存器点结构(点xyzrgbai,
(浮动,x,x)
(浮动,y,y)
(浮动,z,z)
(浮动、强度、强度)
(uint32_t,rgba,rgba)
)

内联std::ostream&operator对于不完整的类型,您可以做的事情很少

如果像以前那样向前声明
结构
,则只能声明指向此类对象的指针:

  • 您甚至不能递增或递减这样的指针,因为这需要编译器知道对象的大小(即知道其声明)
  • 您也不能分配新对象,因为构造函数未知,对齐要求也未知
因此,您必须将结构定义放在标题中:

#define PCL_NO_PRECOMPILE

#ifndef POINTXYZRGBAI_H
#define POINTXYZRGBAI_H

#include <pcl/point_types.h>

struct PointXYZRGBAI{
  PCL_ADD_POINT4D;  // macro in pcl/point_types.h that defines some member functions
  union{
    struct{
      float intensity;
      uint32_t rgba;
    };
    float data_c[4];
  };
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW  // eigen/core seems included in pcl/point_types.h 
} EIGEN_ALIGN_16;

inline std::ostream& operator << (std::ostream& os, const PointXYZRGBAI& p);

#endif
#定义PCL\u无预编译
#ifndef POINTXYZRGBAI_H
#定义点xyzrgbai_H
#包括
结构点xyzrgbai{
PCL\u ADD\u POINT4D;//PCL/point\u types.h中定义一些成员函数的宏
联合{
结构{
漂浮强度;
uint32_t rgba;
};
浮动数据_c[4];
};
EIGEN_MAKE_ALIGNED_OPERATOR_NEW//EIGEN/core似乎包含在pcl/point_types.h中
}本征对准16;

内联std::ostream&operator在不知道
pcl::PointCloud
模板的全部内容的情况下,最可能的答案是该模板试图实例化其参数类的实例,或者以某种需要定义类的方式使用它。声明了一个类型。其成员已落实。在标题中声明您的结构。是!或者递增/递减/减法指针:由于必须知道指针的大小,所以C_ADD_POINT4D是一个技巧,它添加8个成员函数,这些函数构造一些对象并按值返回它们。是否在链接说明中添加了相应的对象文件或库文件?
pcl::PointCloud<PointXYZRGBAI> cl; //Error: arithmetic on a pointer to an incomplete type 'PointXYZRGBAI'
//__alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
// __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
In file included from /Users/wfehrnstrom/Demeter/core.cpp:9:
In file included from /usr/local/include/boost/thread/thread.hpp:12:
In file included from /usr/local/include/boost/thread/thread_only.hpp:17:
In file included from /usr/local/include/boost/thread/pthread/thread_data.hpp:24:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:424:68: error: 
      arithmetic on a pointer to an incomplete type 'PointXYZRGBAI'
        __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
                                                                   ^ ~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:368:29: note: 
      in instantiation of member function
      'std::__1::__vector_base<PointXYZRGBAI,
      Eigen::aligned_allocator_indirection<PointXYZRGBAI> >::__destruct_at_end'
      requested here
    void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:451:9: note: 
      in instantiation of member function
      'std::__1::__vector_base<PointXYZRGBAI,
      Eigen::aligned_allocator_indirection<PointXYZRGBAI> >::clear' requested
      here
        clear();
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:1244:75: note: 
      in instantiation of member function
      'std::__1::__vector_base<PointXYZRGBAI,
      Eigen::aligned_allocator_indirection<PointXYZRGBAI> >::~__vector_base'
      requested here
  ...<class _Tp, class _Alloc> friend class _LIBCPP_TYPE_VIS_ONLY vector;
                                                                  ^
/Users/wfehrnstrom/Demeter/LidarFile.h:20:7: note: in instantiation of member
      function 'pcl::PointCloud<PointXYZRGBAI>::~PointCloud' requested here
class LidarFile{
      ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1527:14: note: 
      in instantiation of function template specialization
      'std::__1::allocator_traits<std::__1::allocator<LidarFile>
      >::__destroy<LidarFile>' requested here
            {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
             ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:424:25: note: 
      in instantiation of function template specialization
      'std::__1::allocator_traits<std::__1::allocator<LidarFile>
      >::destroy<LidarFile>' requested here
        __alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__end_));
                        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:368:29: note: 
      in instantiation of member function 'std::__1::__vector_base<LidarFile,
      std::__1::allocator<LidarFile> >::__destruct_at_end' requested here
    void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
                            ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:451:9: note: 
      in instantiation of member function 'std::__1::__vector_base<LidarFile,
      std::__1::allocator<LidarFile> >::clear' requested here
        clear();
        ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:1244:75: note: 
      in instantiation of member function 'std::__1::__vector_base<LidarFile,
      std::__1::allocator<LidarFile> >::~__vector_base' requested here
  ...<class _Tp, class _Alloc> friend class _LIBCPP_TYPE_VIS_ONLY vector;
                                                                  ^
/Users/wfehrnstrom/Demeter/PointXYZRGBAI.h:9:8: note: forward declaration of
      'PointXYZRGBAI'
struct PointXYZRGBAI;
       ^
In file included from /Users/wfehrnstrom/Demeter/core.cpp:9:
In file included from /usr/local/include/boost/thread/thread.hpp:12:
In file included from /usr/local/include/boost/thread/thread_only.hpp:17:
In file included from /usr/local/include/boost/thread/pthread/thread_data.hpp:24:
#define PCL_NO_PRECOMPILE

#ifndef POINTXYZRGBAI_H
#define POINTXYZRGBAI_H

#include <pcl/point_types.h>

struct PointXYZRGBAI{
  PCL_ADD_POINT4D;  // macro in pcl/point_types.h that defines some member functions
  union{
    struct{
      float intensity;
      uint32_t rgba;
    };
    float data_c[4];
  };
  EIGEN_MAKE_ALIGNED_OPERATOR_NEW  // eigen/core seems included in pcl/point_types.h 
} EIGEN_ALIGN_16;

inline std::ostream& operator << (std::ostream& os, const PointXYZRGBAI& p);

#endif