Skip to content

Instantly share code, notes, and snippets.

@kylemsguy
Last active September 28, 2018 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylemsguy/bc464fb32aa982844ba34be664979efd to your computer and use it in GitHub Desktop.
Save kylemsguy/bc464fb32aa982844ba34be664979efd to your computer and use it in GitHub Desktop.
Vector of Vectors test
#include <cstdio>
#include <vector>
using namespace std;
class Blah {
private:
int a;
public:
Blah(int a){
this->a = a;
}
int get_a(){
return this->a;
}
};
void print_blahs(vector<vector<Blah> > blahs){
for(int i = 0; i < blahs.size(); i++){
for(int j = 0; j < blahs[i].size(); j++){
printf("%d\t", blahs[i][j].get_a());
}
printf("\n");
}
}
int main(int argc, char **argv){
vector<vector<Blah> > *array = new vector<vector<Blah> >();
for(int i = 0; i < 5; i++){
vector<Blah> *row = new vector<Blah>();
for(int j = 0; j < 5; j++){
row->push_back(Blah(i+j));
}
array->push_back(*row);
}
print_blahs(*array);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment