I'm creating my own vector class(for an assignment) here:
private:
T *items;
int used;
Vector() {
used = 0;
items = new T[1000];
};
When I construct the vector and use:
std::cout<<sizeof(items)/sizeof(T);
It returns 1 always, no matter what size I make items in the constructor(I've tried 1000,4,1,0,-1) it always cout's 1. I also try to double the array when it reaches 1000, then 2000 then 4000 etc.
if(used == sizeof(items)/sizeof(items[0])) {
T *tempItems = new T [used];
memcpy(items, tempItems, sizeof(items));
delete []items;
T* items = new T[used*2];
memcpy(tempItems, items, sizeof(items));
delete []tempItems;
}
It throws an invalid read when I try to print out items's contents. This may be due to the previous problem. I cannot go back to using vector's, that's the point of the assignment.