0
我有以下結構vector.push_back()智能感知錯誤
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*>>
代碼看起來編譯罰款,誰知道爲什麼會發生這種情況?
旁註:喜歡'向量<性病::的unique_ptr>'如果可能的話。爲什麼在手動清理內容時使用矢量? –
你能詳細說明你的意思嗎?不是'矢量>'矢量? –
Lunyx
如果你有一個指針的向量,並且這些指針(它們指向的內容)被動態分配,那麼在向量超出範圍之前,你必須遍歷該向量並「刪除」每個向量,否則「丟失」指針以其他方式。該向量不會爲您清理動態分配的內存,它會清理自己的存儲空間。它只是爲一堆指針分配存儲空間。 –