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 / structure array error

Author
Message
Lord Herakles the Great
13
Years of Service
User Offline
Joined: 24th Mar 2011
Location:
Posted: 20th Apr 2011 09:47
I am attempting to create an array of a structure, but I am having an inexplicable error (inexplicable to me, anyway).

Here is the relevant section of the code:


And here is the error:


What really confuses me is that the array for the characters doesn't work, but the one for the cover objects (my game will have a Gears of War style cover system) does work.

Hail to the king baby
I love Evil Dead.
Freedom Fighters
14
Years of Service
User Offline
Joined: 2nd Nov 2009
Location:
Posted: 20th Apr 2011 11:58 Edited at: 20th Apr 2011 11:59
under level you have this


from knowledge and understanding that doesn't work since your not saying how many 'Character' and 'Cover' you want.

is there a certain amount you need per level or is it undefined?

[ FF - Engine ] - Coming Soon...
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 20th Apr 2011 16:09
If you want to allocate them at runtime, do this: struct Cover_Struct *Cover;

You can then allocate it using 'new'. This means you have to delete them though, and the easiest way to do that is to use a destructor in your struct.

Or you could use an std::vector, which will allow you to dynamically resize the array and not have to worry about memory management.

"everyone forgets a semi-colon sometimes." - Phaelax
Tiborko
16
Years of Service
User Offline
Joined: 25th Jul 2008
Location: In front of computer
Posted: 20th Apr 2011 16:14
why don't you use vector instead of array? vectors do better and faster...

Repetitio est mater studiorum!
WLGfx
16
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 20th Apr 2011 16:35
Where you have:


Change to:


When you setup the Level struct use:


also remember to delete them using:


Hope I've typed it up alright and it helps...

Warning! May contain Nuts!
puppyofkosh
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 20th Apr 2011 18:35
Quote: "also remember to delete them using:




Hope I've typed it up alright and it helps..."


But remember to delete with "delete[]" if you allocate with "new[]"
Lord Herakles the Great
13
Years of Service
User Offline
Joined: 24th Mar 2011
Location:
Posted: 21st Apr 2011 09:53
What I want to be able to do is something like this:



Could I use a std::vector to do something like that? How do you use a std::vector? That wasn't covered in the beginner's C course I took or the beginner's C++ book I read.

Hail to the king baby
I love Evil Dead.
Lord Herakles the Great
13
Years of Service
User Offline
Joined: 24th Mar 2011
Location:
Posted: 27th Apr 2011 08:49
If anyone is still curious, I googled C++ vectors and tried to implement them in my code. Unfortunately I couldn't get it to work so I just used arrays with arbitrarily large sizes (1000 was the number I chose, which should be far more than I will ever use in any levels in my game). I guess I'm just not an experienced enough programmer to use vectors right now.

Hail to the king baby
I love Evil Dead.

Login to post a reply

Server time is: 2024-10-02 17:27:11
Your offset time is: 2024-10-02 17:27:11