我有以下结构
struct foo{
vector<foo*> cntns;
};
和以下功能
void createLink(foo *i1, foo *i2){
i1->cntns.push_back(i2);
i2->cntns.push_back(i1);
}
但我得到了错误
2 IntelliSense: no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=foo*, _Alloc=std::allocator<foo*>]" matches the argument list
argument types are: (foo*)
object type is: std::vector<foo*, std::allocator<foo*>>
代码似乎可以很好地编译,有人知道为什么会这样吗?
最佳答案
不确定为什么这是Intellisense错误,因为代码可以编译并且可以正常工作。
但是,如果您真的想摆脱Intellisense错误,我发现使它成为成员函数就摆脱了抱怨:
struct foo
{
vector<foo *> cntns;
void createLink(foo * i2)
{
this->cntns.push_back(i2);
i2->cntns.push_back(this);
}
};
关于c++ - vector.push_back()智能感知错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19393047/