C ++不能直接调用构造函数“ [英] C++ Cannot call constructor ' ' directly

查看:1178
本文介绍了C ++不能直接调用构造函数“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些OpenCV代码,并在VS 2008中在Windows上开发。我试图在Linux上使用g ++运行代码,但我得到错误无法直接调用构造函数ImageProcessor :: ImageProcessor'为ImageProcessor和我创建的所有其他类。我试图找到一种方法来间接调用构造函数,但没有效果。任何建议都是伟大的。该代码在Windows上编译并运行良好。

I'm working on some OpenCV code and developed it in VS 2008 on windows. I'm trying to run the code on Linux with g++ but I get the error "Cannot call constructor 'ImageProcessor::ImageProcessor' directly" for ImageProcessor and all of the other classes I have created. I've attempted to find a way to indirectly call the constructor, but to no avail. Any suggestion would be great. The code compiles and runs fine on Windows.

if (x == 1){
    cout <<"MODE SELECTED: IMAGE TESTING \n";
    ImageProcessor* IP = new ImageProcessor;
    LaneDetector* LD = new LaneDetector;
    LaneInfo* LI1 = new LaneInfo;
    LaneInfo* LI2 = new LaneInfo;
    LaneVector* LV = new LaneVector;
    cvNamedWindow("Window",CV_WINDOW_AUTOSIZE);

    IplImage* temp = 0;
    IplImage* img0 = 0;
    img0 = cvLoadImage(PICTURE_INPUT);
    CvRect r = cvRect(0,((img0->height)/3),img0->width,((img0->height)/3)+20);
    cout <<"IMG0 LOADED \n";

    while(1){
        IP->ImageProcessor::ImageProcessor(img0, r);
        temp = IP->ImageProcessor::get_processed_image();
        LD->LaneDetector::LaneDetector(temp,r);
        LD->LaneDetector::find_edges();
        LI1 = LD->LaneDetector::find_lanes(5);
        LI2 = LD->LaneDetector::find_lanes(25);
        LV->LaneVector::LaneVector(LI1,LI2);
        LV->LaneVector::print_lane_angle_info();

        if( (cvWaitKey(20) & 255) == 27 ) break;
        cvShowImage("Window", temp);
        hold(1);
    }
}


推荐答案

代码是可怕的。

为什么你符合每个成员函数?

Why are you qualifying every member function?

在已创建的对象上的构造函数。当你初始化对象(你的代码用 new ,这也不是好的C ++编码风格)时,应该提供任何构造函数参数。如果这些参数不是在构造之后很长时间才提供的,请将构造函数更改为具有适当名称的正常成员函数。

And no, you can't call a constructor on an already-created object. Any constructor parameters should be provided when you initialize the object (which your code does with new, which is also not good C++ coding style). If these arguments aren't supposed to be provided until long after construction, change the "constructor" into a normal member function with an appropriate name.

您的代码具有大量内存泄漏也。看起来你正在用C ++语法编写Java代码。这不是一件好事。

Your code has numerous memory leaks also. It looks like you're writing Java code with C++ syntax. That's not a good thing.

这篇关于C ++不能直接调用构造函数“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆