Pass 2-D Vector to Class

This is my attempt at passing a 2-D vector of arbitrary element types, inner and outer lengths to a class and printing its contents.
There are a few issues but I'm not quite sure how to resolve.

<
template <typename V, typename I>
class myVec{
private:
I rows;
I cols;
std::vector< std::vector<V> > vec( rows , vector<int> (cols));

public:
myVec(std::vector< std::vector<V> > const &myArr){
vec = myArr;
rows = myArr.size();
cols = myArr[].size();
}
void printVec(){
for(int i = 0; i < vec.size(); i++){
std::cout << "{";
for(int j = 0; j < vec[i].size(); j++){
std::cout << vec[i][j];
}
if (i < vec.size()){
std::cout << "}";
if (i < vec.size()-1){
std::cout << ",";
std::cout << " ";
}
}
}
std::cout << std::endl;
}
};

int main () {
std::vector< std::vector<int> > mainVec = {{1, 2, 4}, {5, 6, 7, 8}, {4, 3, 2, 1, 7}, {8, 7, 6, 5, 9, 3}};
myVec<int, int> vec1 = myVec<int, int>(mainVec);
vec1.printVec();
return 0;
>
Last edited on
Topic archived. No new replies allowed.