Fine, now i want to create my own basic vector and i do:
template <typename T>
class Vector {
T * vector;
int size;
public:
Vector(int pSize = 10) : size(pSize)
{
vector = new T[size];
}
T& operator[](int i)
{
return vector[i];
}
};
So for a one-dimensional vector everything is fine. I can do:
Vector<int> vectorInt(20);
for (int i = 0; i < 20; i++)
vectorInt[i] = i;
for (int i = 0; i < 20; i++)
std::cout << vectorInt[i] << std::endl;
All right, but the problem states when i want to put my vector inside the same vector class, as this:
Vector<Vector<int>> xy(5);
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 10; j++)
{
xy[i][j] = j;
std::cout << xy[i][j] << " ";
}
std::cout << std::endl;
}
The thing is i cannot initialize to a requested size the insider vector (it defaults to 10 as the constructor says). Only the outsider one to "5".
Is there anyway to initialize the insider vector at declaration?