[英]typedef variable in C++
我想问一下C ++中的typedef变量
好的,现在我正在使用PCL,我想将代码分为.h和.cpp
这是我的.h文件
template <typename PointType>
class OpenNIViewer
{
public:
typedef pcl::PointCloud<PointType> Cloud;
typedef typename Cloud::ConstPtr CloudConstPtr;
...
...
CloudConstPtr getLatestCloud ();
...
...
};
然后在其他.cpp文件上定义getLatestCloud()
template <typename PointType>
CloudConstPtr OpenNIViewer<PointType>::getLatestCloud ()
{
...
}
然后我收到C4430错误,因为它无法识别返回类型CloudConstPtr
抱歉这个愚蠢的问题:D
CloudConstPtr
是嵌套类型,因此您还需要使用范围限定它:
template <typename PointType>
typename OpenNIViewer<PointType>::CloudConstPtr OpenNIViewer<PointType>::getLatestCloud ()
{
...
}
但后来它仍然是行不通的:那是因为你已经在定义它.cpp
文件。 如果是模板,则该定义应在.h
文件本身中可用。 最简单的方法是在类本身中定义每个成员函数。 不要写.cpp
文件。
将getLatestCloud
更改为:
template <typename PointType>
typename OpenNIViewer<PointType>::CloudConstPtr
OpenNIViewer<PointType>::getLatestCloud ()
{
...
}
在读取CloudConstPtr
,编译器尚不知道应在哪个范围内查找,因此需要对其进行限定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.