我试图定义我自己的PointT类型,在一个点上给出XYZRGBA和强度值。我试图遵循本文中在点云库网站上列出的约定: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的指针上的算术,就像我声明使用struct PointXYZRGBAI的点云时:
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:
如有任何帮助或澄清,将不胜感激。
发布于 2016-09-03 18:38:39
你可以用不完整的类型做很少的事情。
如果您像以前一样转发声明struct
或class
,则只能声明指向这样一个对象的指针:
因此,您必须将struct定义放在标题中:
#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
功能(和注册宏)的实现应保留在cpp文件中。
https://stackoverflow.com/questions/39310011
复制相似问题