6
Std :: vector :: swap yöntemini kullanarak iki farklı vektörü C ++ 'da değiştirmek güvenli midir?
Aşağıdaki koda sahip olduğunuzu varsayalım: #include <iostream> #include <string> #include <vector> int main() { std::vector<std::string> First{"example", "second" , "C++" , "Hello world" }; std::vector<std::string> Second{"Hello"}; First.swap(Second); for(auto a : Second) std::cout << a << "\n"; return 0; } Vektörün std::stringhenüz sınıf olmadığını hayal edin : std::vector<Widget> WidgetVector; std::vector<Widget2> Widget2Vector; İki …