Re: Simple question on Pointers
- From: Tommy <bad@xxxxxxxxxxxxx>
- Date: Sat, 29 Nov 2008 15:29:23 -0500
Here's a better one:
#define TYPECHAR12(x) char *x = new char[12]
...
TYPECHAR12(p)
Looks like a "type" CHAR12 to me :-)
Lets call it Alan++ <g>
--
Alan Carre wrote:
"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
- 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
- Re: Simple question on Pointers
- From: Alan Carre
- Simple question on Pointers
- Prev by Date: Re: #define and (brackets)
- Next by Date: Re: Simple question on Pointers
- Previous by thread: Re: Simple question on Pointers
- Next by thread: Re: Simple question on Pointers
- Index(es):
Loading