|
programming difficulty |
William Labbett
Member #4,486
March 2004
|
hi, I got a struct and an array of pointers to such structs :- I need to be able to initialise what the pointers point to. If I do this :- (I've only initialised one member deliberately.) Wouldn't this be wrong ? Is there a way to initialise the structs not the pointers ?
|
CGamesPlay
Member #2,559
July 2002
|
(In C) Nope, you can't do that. -- Ryan Patterson - <http://cgamesplay.com/> |
William Labbett
Member #4,486
March 2004
|
That sucks really. I take it you can in C++.
|
CGamesPlay
Member #2,559
July 2002
|
In C++ you can give the struct a constructor and initializing it using new. Although that really isn't practical [append] If you are initializing them that way, why are you using pointers? -- Ryan Patterson - <http://cgamesplay.com/> |
William Labbett
Member #4,486
March 2004
|
To be honest I just thought I aught to. I thought large structures are usually accessed with pointers to save copying them around. Is this wrong ?
|
CGamesPlay
Member #2,559
July 2002
|
No, large structures are allocated using pointers to keep them off the stack, which has limited space. You can take the address of any variable, whether ir was made with malloc, or a local, or a global, or anything. Taking the address of a variable--the same as making a pointer to it--is done like this: struct scenery_object so; struct scenery_object* ptr; ptr = &so;
[append] -- Ryan Patterson - <http://cgamesplay.com/> |
William Labbett
Member #4,486
March 2004
|
Okay thanks CGamesPlay - you're a good man I'll see how I get on without the pointers.
|
|