C++中的typedef变量
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
时,编译器还不知道应该在哪个范围内查找,因此需要对其进行限定。
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- C++:TypeDef使用元组
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 将数组的地址分配给变量并删除
- 为"adjacent"变量赋值时出现问题
- enum是C++中的宏变量还是整数变量
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 用C++中的一个变量定义一个常量
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 你能重载对象变量名本身返回的内容吗
- 内置函数可查看CPP中的成员变量
- 模板类编译问题与 typedef 变量
- 在 CPP 中初始化 typedef 结构变量
- 如何修复 Typedef 变量未识别错误 C++ (Visual Studio 2017)
- 如何通过从变量中获取类型来访问内部 typedef
- 如何在包含 typedef 时用从右到左的规则解释变量声明
- Arduino上的typedef结构:变量没有命名类型
- 在 typedef 上使用 sizeof 而不是局部变量
- C++中的typedef变量
- 如何将typedef变量赋值为静态