【发布时间】:2016-09-03 18:15:35
【问题描述】:
我试图定义我自己的 PointT 类型,以便在一个点上给我 XYZRGBA 和强度值。我尝试在点云库网站上遵循本文中列出的约定:http://pointclouds.org/documentation/tutorials/adding_custom_ptype.php
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);
}
前向声明位于头文件名 PointXYZRGBAI.h 中
#define PCL_NO_PRECOMPILE
#ifndef POINTXYZRGBAI_H
#define POINTXYZRGBAI_H
#endif
#include <pcl/point_types.h>
struct PointXYZRGBAI;
inline std::ostream& operator << (std::ostream& os, const PointXYZRGBAI& p);
从我对结构体的基本理解来看,我需要转发声明结构体,以便编译器在编译过程中理解PointXYZRGBAI确实是一个结构体而不是某种未知类型,然后用实际实现来填补空白。但这似乎受到以下事实的挑战:当我声明任何使用模板类型 PointXYZRGBAI 的成员实例变量时,会引发错误:对指向不完整类型 'PointXYZRGBAI 的指针的算术运算,就像我声明使用该结构的点云时一样点XYZRGBAI:
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_));
似乎在 PointXYZRGBAI 类型上发生了未定义的操作。所以我该怎么做?我是否需要在 LidarFile.h 标头之前以某种方式实现该结构?仅供参考,这里是完整的错误堆栈跟踪:
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:
任何帮助或澄清将不胜感激。
【问题讨论】:
-
在不知道
pcl::PointCloud模板的全部内容的情况下,最可能的答案是该模板试图实例化其参数类的实例,或者以某种需要类的方式使用它已定义。 -
一个 type 是 declared。它的成员是实现的。在标题中声明您的结构。
-
是的!或递增/递减/减去指针:因为必须知道大小
标签: c++ struct instance forward-declaration point-cloud-library