目前,我有以下结构(一个或多个)C++结构错误“没有呼叫匹配功能......”
struct LR0Item{
string lhs;
vector<string> rhs;
int dpos;
};
struct Node{
LR0Item* item;
map<string, Node*> tr;
};
struct my_struct{
bool operator()(
const LR0Item &a,
const LR0Item &b) {
if(a.lhs != b.lhs)
return a.lhs<b.lhs;
if(a.dpos != b.dpos)
return a.dpos<b.dpos;
return a.rhs<b.rhs;
}
};
和下面的代码:
vector<string> test_v; //assume this is filled with various strings
vector<Node*> N;
map<LR0Item,Node*,my_struct> nmap;
LR0Item* Q = new LR0Item("test", test_v, 3); //1 - error occurs here
Node* N1 = new Node(Q); //2 - error occurs here
N.push_back(N1);
nmap[*Q] = N1;
我正在上的错误注释1俗话说:
error: no matching function for call to 'LR0Item::LR0Item(std::string&, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&, int&)'|
note: candidates are: LR0Item::LR0Item()|
note: LR0Item::LR0Item(const LR0Item&)
而且我在评论2俗话说错误:
error: no matching function for call to 'Node::Node(LR0Item*&)'
note: candidates are: Node::Node()|
note: Node::Node(const Node&)
我不完全确定这里发生了什么或如何解决它。
编辑:澄清,不使用C++ 11。
尽管Node构造函数仍然给我一个错误,但LR0Item构造函数仍然有效。 “无法在初始化中将const LR0Item转换为LR0Item *。” – Dohrann
对不起 - 现在应该是*了 - –
由于某种原因,它不喜欢Node构造函数中的'const'。考虑到这一点,它的效果很好。你能解释为什么吗? – Dohrann