0

我有以下结构

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*>>

代码似乎编译得很好,有人知道为什么会这样吗?

4

1 回答 1

1

不知道为什么这是一个 Intellisense 错误,因为代码可以编译并正常工作。

但是,如果您真的想摆脱 Intellisense 错误,我发现将其设为成员函数可以消除抱怨:

struct foo
{
    vector<foo *> cntns;

    void createLink(foo * i2)
    {
        this->cntns.push_back(i2);
        i2->cntns.push_back(this);
    }
};
于 2013-10-16T16:34:55.340 回答