Creating C-style array of size zero from pointer

rof3

Member
Aug 31, 2004
119
0
0
We are rewriting the Vector class for my C++ class, and I stupidly left my notes at school (home for Easter). I have a T* contents and in the default constructor I need to make it a C-style array of size zero. I think it was something like contents = new Array(0) but I'm not sure, and if Google knows it's not telling. Can anyone help me out? Thanks.
 

Zugzwang152

Lifer
Oct 30, 2001
12,134
1
0
well i'm not sure exactly how to implement this, but something makes me think this is a trick question. A C-style array is just a pointer to the first object of the array. Accessing items in the array in C just causes C to look sizeof(arraytype)*index bytes in memory from the location stored in the pointer. Hence if you're given a pointer, you technically have an array already :p
 

rof3

Member
Aug 31, 2004
119
0
0
Yeah I know...but that's how the prof. told us to do it, and he gave us the syntax, I just forgot what it was and left my notes at school. Let me reprhase about being "given" a pointer...my prof gave us the class definition and stubs, and the class definition he gave us included the private T pointer contents. So I need to do something like contents = new array but I don't know the specific syntax. Maybe it's contents = new T[0];?

Edit: Ah yes, I think that might be it (confirmation appreciated though ;) ). Just found something similar looking here, about a fifth of the way down.
 

Zugzwang152

Lifer
Oct 30, 2001
12,134
1
0
Originally posted by: BingBongWongFooey
Why bother to make an array of 0? Why not just point the pointer at NULL while the vector is empty?

it's a class exercize, that's why :p