|
Prev: initialising built in types with curly braces
Next: Mapping Templates function betweeen 2 class
From: barss on 24 Apr 2008 06:19 On Apr 23, 8:00 pm, "sk_usenet" <sometechyguy at gmail dot com> wrote: > "Pat" <pkelecy@_REMOVETHIS_gmail.com> wrote in message > >I have a question about the new operator. The syntax for it is: > > > int * pointer = new int; > > > which says that "pointer" points to a type int variable. > > > My question is why is "int" needed twice? I know it's needed from a > > syntax standpoint, but I don't understand what additional information the > > second int really provides. Doesn't the first int already tell you that > > an int type value is going to be stored at the "pointer" address? > > What about arrays? > int *p = new int[10]; > > > Can you ever have, > > > int * pointer = new double > > No, realize that new operator is returning a double*, and heance trying to > assign to an int* is not legal. > > > or something like that? > > Thanks for any feedback on this. > > --http://techytalk.googlepages.com never mind. You use "int" to store pointer. This trick will be work for 32 bit platforms because size of any pointer will be 4 bytes. But for 64 bit platforms you will have a problem, because size of any pointer will be more than 4 bytes. You can see note also about pointer to int conversion when compiling.
From: Francis Glassborow on 24 Apr 2008 06:38 barss wrote: > On Apr 23, 8:00 pm, "sk_usenet" <sometechyguy at gmail dot com> wrote: >> "Pat" <pkelecy@_REMOVETHIS_gmail.com> wrote in message >>> I have a question about the new operator. The syntax for it is: >>> int * pointer = new int; >>> which says that "pointer" points to a type int variable. >>> My question is why is "int" needed twice? I know it's needed from a >>> syntax standpoint, but I don't understand what additional information the >>> second int really provides. Doesn't the first int already tell you that >>> an int type value is going to be stored at the "pointer" address? >> What about arrays? >> int *p = new int[10]; >> >>> Can you ever have, >>> int * pointer = new double >> No, realize that new operator is returning a double*, and heance trying to >> assign to an int* is not legal. >> >>> or something like that? >>> Thanks for any feedback on this. >> --http://techytalk.googlepages.com > > never mind. You use "int" to store pointer. This trick will be work > for 32 bit platforms because size of any pointer will be 4 bytes. But > for 64 bit platforms you will have a problem, because size of any > pointer will be more than 4 bytes. You can see note also about pointer > to int conversion when compiling. Please explain what this has to do with the question. Nothing above said anything about storing pointers in ints.
First
|
Prev
|
Pages: 1 2 Prev: initialising built in types with curly braces Next: Mapping Templates function betweeen 2 class |