首页 文章

在此范围内未声明C构建错误

提问于
浏览
-4

我在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 回答

  • 2

    好吧,就像它说: SimpleOpenNIProcessor 未在您尝试实例化它时声明 .

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

    有关更多信息,请阅读您的C书 .

相关问题