Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Arrays, Classes ... Error?

Author
Message
Doran
15
Years of Service
User Offline
Joined: 5th Jun 2009
Location:
Posted: 12th Jun 2009 12:22
Ok I'm new to both DarkGDK and C++ so i'm sure i'm doing this all wrong.

All I want to do is be able to create an instances of a "man"'s with their own properties so they can be controlled seperatly at any time. The "Man" has his own 3D model so I will need to duplicate the model for that one "Man".

Now the problem is in Man::Create() it won't let me make a Man because I'm using a variable so I can keep a array of all the "Man"'s.

The full code is here:


Any sort of help or code would be very much appreciated!!!
AlexI
19
Years of Service
User Offline
Joined: 31st Dec 2004
Location: UK
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 12th Jun 2009 18:13
You do realize that any variables, including arrays that are created inside a function tend to disappear when the program exits that function because it's created on the stack, not the heap or static memory.

If you want to create an array that remains beyond the life of the function you need to declare it as static. However, because of its scope you can only see it inside the function and won't be able to access it from elsewhere in the class. If you want it to be visible to the rest of the class you would have to declare it as a member of the class. If you only want the object to see the array, all's set. But if you want the array to be shared between all objects of the same class you need to declare it as a static class member.

But arrays are difficult to re-dimension, so if you're looking at being able to add more objects to an existing collection, try looking at std::vector as a beginning. I have several examples of using them to track all objects in a class in my latest entry to the Dark GDK Challenge.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Doran
15
Years of Service
User Offline
Joined: 5th Jun 2009
Location:
Posted: 13th Jun 2009 02:41
Ah! thanks Lilith. I forgot about that when I was writing the code. I'm going to try a few things and see if I can get it to work.

Cheers!

Login to post a reply

Server time is: 2024-10-01 03:38:25
Your offset time is: 2024-10-01 03:38:25