Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it recommended to specify e.g. vector<t> in my public interface?

I'm new to C++, and while writing a class I realized one of my methods was asking for a vector-of-vectors. Should this be done or should I rethink my class's interface? (How?)

like image 341
J Cooper Avatar asked Aug 02 '11 02:08

J Cooper


1 Answers

I think it is no problem what container you use. You could do it like

void func(std::vector<std::vector<int> > const& int_matrix);

or in C++11, successive > won't be considered as '>>' so you could also use

void func(std::vector<std::vector<int>> const& int_matrix);

But the problem is, if your work are published as binary instead of source code, the users of the interface should have the same STL implement as yours, otherwise strange runtime errors may occur. So use STL container as interface is not proper in this situation. You have to define some structures yourself as the type of parameters.

like image 92
neuront Avatar answered Nov 15 '22 07:11

neuront