C++ compiler complaining about no default constructor

随声附和 提交于 2021-02-11 13:59:14

问题


Given this struct with a private stateful variable:

struct Calibrate
{
private:
    Stitcher stitcher_obj_;

}

This is the stitcher object (with empty constructor):

Stitcher::Stitcher(const std::vector<cv::Mat> &src_images){}

When calling Calibrate, I am getting this error:

default constructor of 'Calibrate' is implicitly deleted because field 'stitcher_obj_' has no default constructor
Stitcher stitcher_obj_
         ^

Thanks for any suggestions on how to fix this!


回答1:


As soon as you provide a custom constructor for a class, the default constructor (the 0 argument constructor) is no longer synthesized. You need to reinstate it manually, like this:

class Stitcher {
  Stitcher() = default;
  // ...
};


来源:https://stackoverflow.com/questions/61764719/c-compiler-complaining-about-no-default-constructor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!