Reputation: 13
vector< vector< vector<int> > > myArray(5, vector< vector<int> >(4));
vector<int> testArray();
myArray[0][0].push_back(testArray);
I don't understand. I'm just trying to append a new element to it.
Edit: Second line was wrong but this still doesn't compile.
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector< vector< vector<int> > > myArray(5, vector< vector<int> >(4));
vector<int> testArray;
myArray[0][0].push_back(testArray);
return 0;
}
The compile error:
pnt.cpp: In function ‘int main()’: pnt.cpp:8: error: no matching function for call to ‘std::vector >::push_back(std::vector >&)’ /usr/include/c++/4.4/bits/stl_vector.h:733: note: candidates are: void std::vector<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = int, _Alloc = std::allocator]
Upvotes: 1
Views: 5423
Reputation: 143
myArray is a vector of vector of vector of int. myArray[0] is a vector of vector of int. This is where you need to push_back your vector of int, like so:
std::vector< std::vector< std::vector<int> > > myArray(5, std::vector< std::vector<int> >(4));
std::vector<int> testArray;
myArray[0].push_back(testArray);
return 0;
With myArray[0][0] you are accessing the vector of int, not vector of vector of int.
Upvotes: 1
Reputation: 91320
vector<int> testArray();
Should be:
vector<int> testArray;
vector<int> testArray();
is a forward declaration of a function called testArray
which returns vector<int>
.
You also have one level of indirection too much:
myArray[0].push_back(testArray);
or
myArray[0][0] = testArray;
Upvotes: 9