+ 2
STL vector<int> push_back() method
suppose i have the following type vector<int> v1; in normal case , push_back(int ) but i need , v1.push_back(vector <int>); //need to overload push_back() to push_back(vector <int>)
1 ответ
+ 3
Something like this also works:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<vector<int>> twoD;
twoD.push_back({1,2,3,4,5});
twoD.push_back({6,7,8,9,10});
vector<int> data{11,12,13,14,15};
twoD.push_back(data);
return 0;
}
If you want to override then:
https://stackoverflow.com/questions/13836881/overriding-push-back-c