本文介绍了C ++编译器抱怨没有默认构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给这个结构一个私有的有状态变量:
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){}
调用 Calibrate
时,出现此错误:
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!
推荐答案
为类提供自定义构造函数后,将不再合成默认构造函数(参数为0的构造函数).您需要像这样手动恢复它:
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;
// ...
};
这篇关于C ++编译器抱怨没有默认构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!