gpt4 book ai didi

c++ - vector.push_back() 智能感知错误

转载 作者:行者123 更新时间:2023-11-28 07:21:29 24 4
gpt4 key购买 nike

我有以下结构

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com