Re: creating a vector of a vector of Gtk::ToggleButton



>Ok guys, I would best describe myself as a budding stl programmer.  I 
>have a situation where I need a matrix of toggle buttons but rather than 
>use an array I'm using a vector of vectors.  The error looks to me like 
>the Gtk::ToggleButton's copy constructor is declared as private but that 
>seems weird.  Here's my code: 

one thing the docs on the STL doesn't really make clear is that if you
are using containers of objects that actually "consume" real
resources, its generally wise to use containers of pointers
instead. even if the object does provide a copy constructor, the act
of making a copy is not necessarily cheap enough for it to be used so
freely. hence:
	
	typedef std::vector<Gtk::ToggleButton*> chiprow;
	std::vector<chiprow*> _chips;

your mileage may vary as to whether you consider a ToggleButton to
have "weight". note that this approach also means that vector::clear()
(and container::clear() in general) does *not* free the objects
pointed to, which can be problematic sometimes.

--p



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]