没有匹配功能来调用功能' /将结构向量传递给函数

时间:2017-09-27 08:21:39

标签: c++ function struct

我正在尝试显示结构向量的内容。 但是我在显示它们时遇到了问题

  

这是我的结构

struct tDetection {
        tBox    box;    // object type, box, orientation
        double  thresh; // detection score
        double  ry;
        double  t1, t2, t3;
        double  h, w, l;
};
  

显示struct

的功能
void displayDetection(struct tDetection& param) {
    cout << param.type << param.x1 << param.y1 << param.x2 << param.y2 << param.alpha << endl;
    cout << param.thresh << param.ry <<endl;
    cout << param.t1 << param.t2 << param.t3 <<endl;
    cout << param.h << param.w << param.l << endl; 
}

当我运行此功能时,错误信息是:没有用于调用&#39; displayDetection&#39;的匹配功能。

  

另一个调用显示功能的函数

bool eval(){

// set some global parameters
    initGlobals();

    // ground truth and result directories
    string gt_dir         = "/Users/Documents/c++/eval_too/eval_too/data/object/lable_2";
    string result_dir     = "/Users/Documents/c++/eval_too/eval_too/result/result_sha"; // results
    string plot_dir       = result_dir + "/plot";

    // create output directories
    system(("mkdir " + plot_dir).c_str());

    // hold detections and ground truth in memory
    vector< vector<tGroundtruth> > groundtruth;
    vector< vector<tDetection> >   detections;

    bool compute_aos=true;
    vector<bool> eval_image(NUM_CLASS, false);
    vector<bool> eval_ground(NUM_CLASS, false);
    vector<bool> eval_3d(NUM_CLASS, false);

    // for all images read groundtruth and detections
    for (int32_t i=0; i<N_TESTIMAGES; i++) {

        // file name
        char file_name[256];
        sprintf(file_name,"%06d.txt",i);

        // read ground truth and result poses
        bool gt_success,det_success;
        vector<tGroundtruth> gt   = loadGroundtruth(gt_dir + "/" + file_name,gt_success); // ** just follow them; no need to change
        vector<tDetection>   det  = loadDetections(result_dir + "/data/" + file_name,
                                                   compute_aos, eval_image, eval_ground, eval_3d, det_success); // ** change to my format

        // ** add element to the vectors
        groundtruth.push_back(gt);
        detections.push_back(det);

        // check for errors
        if (!gt_success) {
            // mail->msg("ERROR: Couldn't read: %s of ground truth. Please write me an email!", file_name);
            cout << "ERROR: Couldn't read ground truth of file : " << file_name << endl;
            return false;
        }
        if (!det_success) {
            //mail->msg("ERROR: Couldn't read: %s", file_name);
            cout << "ERROR: Couldn't read detection of file : " << file_name << endl;
            return false;
        }
    }

    displayDetection(detections[0]);
}

1 个答案:

答案 0 :(得分:0)

detections[0]为您提供const& tdetection;但是你的函数被声明为非const:void displayDetection(struct tDetection& param)

将其更改为void displayDetection(const struct tDetection& param),它会起作用(它实际上不需要非const,因为除了阅读它之外你没有做任何事情。)