Mail Archives: djgpp/1998/08/15/11:15:34
I'm not exactly sure about what you're saying... but, maybe this will
help:
myobject *obinst; //Global Declaration
int main(void){//or whatever function it's declared in
objinst=(myobject *)new(sizeof(myobject)*sizeofarray);
...
...
...
}//end of function
Ansawddex wrote:
>
> Is there a way of declaring an object to be global when declaring it within a
> function?
>
> My problem is that the game I'm writing doesn't know how many objects it needs
> to declare in a series of object arrays (deliberately done) until it loads the
> current level map. As a result, I have a function that goes through each item
> in
> the map and declares a new element within an object array where necessary.
>
> However, I keep getting an undeclared variable error (or similar) if I try to
> use the
> new arrays in another function.
>
> There are ways around the problem but they're not too elegant. I'd prefer it if
> there
> was a way to make these object arrays global without having to declare them
> at the start of the program.
>
> Any help would be appreciated.
>
> Regards,
> David
--
-------------------
See Ishpeck's Programming page!
Example source, Utils, links,
and help on your programs.
http://members.xoom.com/ishpeck/
tions to verify my results:
>
> 1) A simple test program:
> int main(void) {
> char *string1=(char *)malloc(80);
> char *string2;
>
> strcpy(string1,"foobar");
>
> string2 = string1;
>
> strcpy(string2,"raboof");
>
> printf("%s\n",string1);
> return(0);
> }
>
> This yielded 'raboof' to my delight... Now, have I found a good use for
> pointers? Or is this bad bad code?
>
> 2) Having not initialized string2, a) do I have to free string2 and b) does
> that have any effect on string1? (oops didn't free string1)
>
> 3) concerning strcpy...is there any special reason why I shouldn't just use
> string1 = "foobar" ?
>
> If the answers to these questions are what I think they are my pointer
> dilemmas are over... (game still crashes though :( )
>
> - Cephaler -
>
> p.s. thanks! <-- insert in previous messages as well
--
-------------------
See Ishpeck's Programming page!
Example source, Utils, links,
and help on your programs.
http://members.xoom.com/ishpeck/
- Raw text -