Re: Simple question on Pointers
- From: "Alan Carre" <alan@xxxxxxxxxxxxxxxxx>
- Date: Sun, 30 Nov 2008 03:09:11 +0700
"Tommy" <bad@xxxxxxxxxxxxx> wrote in message
news:O2PB1qlUJHA.5952@xxxxxxxxxxxxxxxxxxxxxxx
Alan Carre wrote:
"Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote in message I don't know what a
"char[12]" is. Perhaps you're thinking we're talking about FORTRAN or
something. There is no such thing as a char[12] as far as the C++
language is concerned.
How about?
char *p = new char[12];
Hehe, astonishing! Where'd you get that MVP from?
You DO know that that is how to specify a Type* using the "new" operator and
is entirely a feature of "new". In this case char[12] is not a type, it is a
collection of parameters passed to the new operator.
The way it works is like this:
T* pT = new Type[Size];
This is how we allocate an array dynamically using "new". "Type" is an
actual C++ type, and Size is a "size_t". The brackets are special indicators
which tell the compiler to insert 'secret' code allowing for the use of
delete[] (vector deleting destruction) for non-trivial types (if you go and
look at the assembler code generated you'll see it allocates some extra
space to store the size of the array, meaning that when you use delete[],
the destructors of the individual elements pointed to by pT can be called).
Would you consider std::map's use of the square bracket operator proof that
if you put a type before some square brackets and an int, that that
expression is a novel C++ type?
class NewType : public std::map<int, int > {}
NewType[13];
The above is not a type, it is an expression.
- Alan Carre
.
- Follow-Ups:
- Re: Simple question on Pointers
- From: Doug Harrison [MVP]
- Re: Simple question on Pointers
- From: Tommy
- Re: Simple question on Pointers
- References:
- Simple question on Pointers
- From: Robby
- Re: Simple question on Pointers
- From: Alan Carre
- Re: Simple question on Pointers
- From: Doug Harrison [MVP]
- Re: Simple question on Pointers
- From: Alan Carre
- Re: Simple question on Pointers
- From: Tommy
- Simple question on Pointers
- Prev by Date: Re: Simple question on Pointers
- Next by Date: Re: #define and (brackets)
- Previous by thread: Re: Simple question on Pointers
- Next by thread: Re: Simple question on Pointers
- Index(es):