• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Creating C-style array of size zero from pointer

rof3

Member
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.
 
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 😛
 
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.
 
Back
Top