Create a vector of grid with Gtkmm

163 views Asked by At

I am working with the library Gtkmm in C++. But I wonder if I can create a vector of a Grid for instance? I mean in C++ I can create a vector of int and add an element dynamically with the method push_back(). Is it possible to do the same with Gtkmm?

Thank you for your help.

2

There are 2 answers

0
torkleyy On

Vectors have template parameters.

Just do something like that:

#include <gtkmm/grid.h>
#include <vector>

std::vector<Gtk::Grid> myGridVector;
//          ^^^^^^^^^^
//          This is the template parameter

You could replace this template parameter with any other concrete type and you'll have a vector of that type.

0
craesh On

You can create a vector of any type you want in C++. Of integers, floats, enums, structs, classes, etc. Your Grid is a class, and as such, you can create a vector of that. See torkleyy's answer for an example.