首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在C++中声明私有变量

在C++中声明私有变量
EN

Stack Overflow用户
提问于 2015-09-27 23:10:14
回答 2查看 1.7K关注 0票数 0

我想创建一些私有变量,但是当我编译程序时,我得到了一个错误。如果我将变量移到SimpleOpenNIViewer类的上面,它就会起作用。

这是错误消息: /Workspace/virtual-reality/main.cpp:16:56: error:‘new’PointCloud::Ptr cloud_previous2 (new PointCloud)之前的预期标识符;

这就是我写代码的方式。谁能告诉我为什么这个不起作用?

代码语言:javascript
复制
class SimpleOpenNIViewer
     {
        private:
            PointCloud<PointXYZRGBA>::Ptr cloud_previous2 (new PointCloud<PointXYZRGBA>);
            PointCloud<PointXYZRGBA>::Ptr cloud_previous1 (new PointCloud<PointXYZRGBA>);
            PointCloud<PointXYZHSV>::Ptr cloud_HSVPrev2(new PointCloud<PointXYZHSV>);
            PointCloud<PointXYZHSV>::Ptr cloud_HSVPrev1(new PointCloud<PointXYZHSV>);
            PointCloud<PointXYZHSV>::Ptr cloud_HSVCurr(new PointCloud<PointXYZHSV>);
EN

回答 2

Stack Overflow用户

发布于 2015-09-27 23:14:48

确保你已经包含了你的变量所依赖的所有相关的头或者转发声明的类。

您的类声明也缺少右大括号和分号。

票数 0
EN

Stack Overflow用户

发布于 2015-09-27 23:15:20

试试这个:

代码语言:javascript
复制
class SimpleOpenNIViewer
     {
        private:
            PointCloud<PointXYZRGBA>::Ptr cloud_previous2 = new PointCloud<PointXYZRGBA>;
            PointCloud<PointXYZRGBA>::Ptr cloud_previous1 = new PointCloud<PointXYZRGBA>;
            PointCloud<PointXYZHSV>::Ptr cloud_HSVPrev2 = new PointCloud<PointXYZHSV>;
            PointCloud<PointXYZHSV>::Ptr cloud_HSVPrev1 = new PointCloud<PointXYZHSV>;
            PointCloud<PointXYZHSV>::Ptr cloud_HSVCurr = new PointCloud<PointXYZHSV>;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32809358

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档