I stand corrected. std::vector does also keep a separate allocation size, for better performance. Probably a good idea to do it in yours as well, so that you can implement a "size()" function, which is pretty important for a vector class, and not very friendly if it doesn't reflect the number of elements actually in the vector.sje wrote:First, instances are NOT the same size:
You are doing something vectors are not designed to do - accessing it past the end.Not very friendly, is it?
If you do something your Vector class is not designed to do, it won't be very friendly either.
Code: Select all
Vector<int> v;
v[-1] = 0;
Code: Select all
Vector<int> v1;
Vector<int> v2;
v1[5] = 3;
v2 = v1;
v2[5] = 9;
std::cout << v1[5] << std::endl; // HUH?
Also, what if T is not copyable? For example, if it's a file stream or thread handle? Though to be fair, that can't be solved before C++11.