--- In [email protected], Christopher Coale <chris95...@...> wrote: > > Brett McCoy wrote: > > > > > > On Mon, Mar 15, 2010 at 8:43 PM, nimak247 <nimak...@... > > <mailto:nimak247%40yahoo.com>> wrote: > > > > > Thanks Sumant!! > > > > > > If I may ask a follow up question, how does the following line work: > > > myT test = (myT)new myT; > > > > > > It looks like it is casting the type before the 'new' operator?? > > > > > > Any help would be appreciated! > > > > It is wrong. new does not require a cast. When using new with a > > struct, is uses a default constructor (just like with a class). > > Casting is totally unnecessary. > > > > -- Brett > > ---------------------------------------------------------- > > "In the rhythm of music a secret is hidden; > > If I were to divulge it, it would overturn the world." > > -- Jelaleddin Rumi > > > > > But it isn't allocating a new struct. It is allocating a pointer. I > think the OP is confused with the declaration for the structure... I > would expect to see something like: > > typedef struct MYTYPE { > ... > } *LPMYTYPE; > > not > > typedef struct { > ... > } *MYTYPE; >
Thanks everyone for the new replies! Yeah, I am a bit confused by the whole thing in this case. Christopher you are right, I did leave out the name of the stuct! What's weird is that what Sumant gave me appears to work without the struct name. That being there makes more sense to me though. As to the line he changed, it looked weird to me in that the right hand side of the assignment statement has a structure of: "(typename) new typename" Which I thought was maybe using a cast to tell the compiler the size to allocate since I didn't see a sizeOf component to the statement... If I may ask a follow up question to what some of you mentioned: Several of you who replied seem to feel that you shouldn't use pointers in c++ anymore... Was this more of a statement about how everything is going managed code (frameworks like .Net, JVM, etc) vs native? Or did you mean that you should just use classes and pass them as objects? It's just that a lot of folks were wondering why I was even attempting to do this, so I am just curious as to what the more proper and/or current approach would be... Nim,
