Reputation: 1942
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'
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)
Target: x86_64-apple-darwin15.3.0
Thread model: posix
Upvotes: 0
Views: 138
Reputation: 320391
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. Such argument cannot be passed to your copy constructor. Hence the error.
Upvotes: 3