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 / Resize array

Author
Message
Dimension
20
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 22nd Jul 2010 10:40
I am trying to create a function that will assign names to objects instead of numbers and need to create a function to resize an array. Does anybody have any clue how I would create a function to resize an array?
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 22nd Jul 2010 12:49
You may want to look at some other form of collection other than an array.
STL Containers

It sounds like you may want a map, if you are not familiar with these containers then you may find them difficult at first but its worth learning to use them, arrays have their uses but the uses are limited.

A map may be declared something like this:

This will hold a name for all each of your object ID's.

Dimension
20
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 23rd Jul 2010 03:38
Could you explain how to insert a name in the container.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 23rd Jul 2010 15:11
map.insert(pair<typeA, typeB>(a, b));

"everyone forgets a semi-colon sometimes." - Phaelax
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 23rd Jul 2010 15:32
If you are using a map then you should be able to do something like this:


This adds an element to your map with key '14' and value 'name'.

You can access each objects name like this:

Not tested, someone tell me if I'm doing something wrong, I'm not great with char*

Login to post a reply

Server time is: 2024-07-04 09:31:53
Your offset time is: 2024-07-04 09:31:53