未在此范围内声明C ++ Build错误

时间:2015-08-24 21:41:04

标签: c++

我正在用C ++编写一个小程序。我创建了2个文件" Main.cpp"和" openni_grabber.cpp"。正如你从代码中看到的那样,我从主要线程开始一个线程。一旦我尝试构建,我收到一条错误消息:' SimpleOpenNIProcessor'未在此范围内声明。

在代码中我需要声明SimpleOpenNIProcessor吗?

Main.cpp的

#include <pcl/io/openni_grabber.h>
#include <pcl/visualization/cloud_viewer.h>

int main()
{
    SimpleOpenNIProcessor v;
    v.run();
    return(0);
}

openni_grabber.cpp

#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/io/openni_grabber.h>
#include <pcl/common/time.h>

class SimpleOpenNIProcessor
{
    SimpleOpenNIProcessor()
    {
    };

    public:
    void cloud_cb_ (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr &cloud)
    {
        static unsigned count = 0;
        static double last = pcl::getTime ();
        if (++count == 30)
        {
            double now = pcl::getTime ();
            std::cout << "distance of center pixel :" << cloud->points [(cloud->width >> 1) * (cloud->height + 1)].z << " mm. Average framerate: " << double(count)/double(now - last) << " Hz" <<  std::endl;
            count = 0;
            last = now;
        }
    }

    void run ()
    {
        // create a new grabber for OpenNI devices
        pcl::Grabber* interface = new pcl::OpenNIGrabber();

        // make callback function from member function
        boost::function<void (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&)> f =
            boost::bind (&SimpleOpenNIProcessor::cloud_cb_, this, _1);

        // connect callback function for desired signal. In this case its a point cloud with color values
        boost::signals2::connection c = interface->registerCallback (f);

        // start receiving point clouds
        interface->start ();

        // wait until user quits program with Ctrl-C, but no busy-waiting -> sleep (1);
        while (true)
        boost::this_thread::sleep (boost::posix_time::seconds (1));

        // stop the grabber
        interface->stop ();
    }
}

1 个答案:

答案 0 :(得分:2)

嗯,正如它所说:SimpleOpenNIProcessor未在您尝试实例化时声明。

我们通常将类定义放在头文件中,以方便地将它们洒在我们的项目周围。

有关更多信息,请阅读您的C ++书籍。