简体   繁体   English

尝试调用默认构造函数时,没有匹配的构造函数

[英]No matching constructor while trying to call default constructor

In my code I have a class with following structure: 在我的代码中,我有一个具有以下结构的类:

 struct AutomatonNode {
    ...
    AutomatonNode();
    AutomatonNode(AutomatonNode &node);
    ...
};

Default constructor has following realisation: 默认构造函数具有以下实现:

AutomatonNode::AutomatonNode() :
    suffixLink(-1),
    len(0) {};

However, during compilation I get the following error: 但是,在编译过程中出现以下错误:

No matching constructor for initialization of 'SA::AutomatonNode' 没有匹配的构造函数,无法初始化'SA :: AutomatonNode'

in this method: 在这种方法中:

size_t SuffixAutomaton::newState() {
    AutomatonNode node;
    nodes.push_back(node);
    return nodes.size() - 1;
}

Looks extremely strange to me, since everything is in place and the constructor is public(it's a struct and by default all fields are public). 对我来说,这看起来很奇怪,因为一切就绪,构造函数是公共的(它是一个结构,默认情况下所有字段都是公共的)。 Any ideas? 有任何想法吗?

For clearance: 清除:

Apple LLVM version 7.3.0 (clang-703.0.31) Apple LLVM版本7.3.0(clang-703.0.31)

Target: x86_64-apple-darwin15.3.0 目标:x86_64-apple-darwin15.3.0

Thread model: posix 螺纹型号:posix

The error has nothing to do with default constructor. 该错误与默认构造函数无关。 (What made you think it did?) (是什么让您认为做到了?)

The problem is most likely caused by your copy constructor accepting its argument as non-const reference. 该问题很可能是由于您的副本构造函数接受其参数作为非常量引用而引起的。 (It is impossible to say for sure since you provided no information about what nodes is.) If nodes is a standard container, then standard push_back accepts its argument as a reference to const. (由于您没有提供有关nodes是什么的信息,因此无法确定。)如果nodes是标准容器,则标准push_back接受其参数作为对const的引用。 Such argument cannot be passed to your copy constructor. 这样的参数不能传递给您的副本构造函数。 Hence the error. 因此,错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM