Click here to Skip to main content
16,011,436 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralInputBox... Pin
Raza568019-Jul-05 20:55
Raza568019-Jul-05 20:55 
GeneralRe: InputBox... Pin
Marc Soleda19-Jul-05 21:00
Marc Soleda19-Jul-05 21:00 
GeneralRe: InputBox... Pin
khan++19-Jul-05 21:09
khan++19-Jul-05 21:09 
GeneralRe: InputBox... Pin
toxcct19-Jul-05 22:33
toxcct19-Jul-05 22:33 
GeneralRe: InputBox... Pin
David Crow20-Jul-05 3:07
David Crow20-Jul-05 3:07 
General2D array for class pointers objects. Help! Pin
Member 341989119-Jul-05 20:50
Member 341989119-Jul-05 20:50 
GeneralRe: 2D array for class pointers objects. Help! Pin
toxcct19-Jul-05 22:40
toxcct19-Jul-05 22:40 
GeneralRe: 2D array for class pointers objects. Help! Pin
John R. Shaw20-Jul-05 9:24
John R. Shaw20-Jul-05 9:24 
Here's some thoughts.
1) std::vector<std::vector<Test*> > my_2D_array;
2) std::map<std::pair<int,int>,Test*> my_map;

In both these cases you would still need to use new. But you can avoid that by letting the standard container do the allocation its self, by using one of these instead:

1) std::vector<std::vector<Test> > my_2D_array;
2) std::map<std::pair<int,int>,Test> my_map;

Vector is faster, but you should reserve space for the number of rows required and then reserve space for each individual row (columns). A bit of a pain, but a simple helper function can do that for you. Or you could just encapsulate the vector of vectors in your own class and use that to access it.

Map is slower, but easier to use. You can't, nor do you need to, reserve space ahead of time. To add a new item just do this:
my_map[std::make_pair(0,0)] = Test();

Note: If the key pair already exist in the map then it is replaced by the new element. If the key pair does not exist, it is add to the map.

When using standard containers you do not have to store pointers to classes, just make the class type the type that is being stored. That way you are not responsible for the clean up and the container is responsible for most of the type safety garantees.

Oh well, I hope that gave you some help.

INTP
Use standard containers when available, unless you have a very good reason to roll your own.
GeneralGina Problem Pin
Anonymous19-Jul-05 20:50
Anonymous19-Jul-05 20:50 
GeneralChanging Picture Pin
Halawlaws19-Jul-05 20:26
Halawlaws19-Jul-05 20:26 
GeneralRe: Changing Picture Pin
toxcct19-Jul-05 22:44
toxcct19-Jul-05 22:44 
GeneralRe: Changing Picture Pin
David Crow20-Jul-05 3:16
David Crow20-Jul-05 3:16 
GeneralRe: Changing Picture Pin
Halawlaws20-Jul-05 3:17
Halawlaws20-Jul-05 3:17 
Generalloading bitmaps from List Box Pin
a_david12319-Jul-05 19:28
a_david12319-Jul-05 19:28 
GeneralRe: loading bitmaps from List Box Pin
David Crow20-Jul-05 3:11
David Crow20-Jul-05 3:11 
GeneralOpen Files Pin
Anonymous19-Jul-05 19:09
Anonymous19-Jul-05 19:09 
GeneralRe: Open Files Pin
22491719-Jul-05 19:57
22491719-Jul-05 19:57 
GeneralConvert mm(millimeter) into pixels for use with TextOut Pin
wasife19-Jul-05 19:09
wasife19-Jul-05 19:09 
GeneralRe: Convert mm(millimeter) into pixels for use with TextOut Pin
Marc Soleda19-Jul-05 20:10
Marc Soleda19-Jul-05 20:10 
GeneralRe: Convert mm(millimeter) into pixels for use with TextOut Pin
RicoH20-Jul-05 0:42
RicoH20-Jul-05 0:42 
GeneralScreen Capture Pin
dSolariuM19-Jul-05 18:14
dSolariuM19-Jul-05 18:14 
GeneralRe: Screen Capture Pin
nm_11419-Jul-05 19:55
nm_11419-Jul-05 19:55 
GeneralRe: Screen Capture Pin
vishalmore20-Jul-05 1:26
vishalmore20-Jul-05 1:26 
GeneralRe: Screen Capture Pin
dSolariuM21-Jul-05 0:00
dSolariuM21-Jul-05 0:00 
GeneralUsing Microsoft computer login dialog Pin
astibich219-Jul-05 17:07
astibich219-Jul-05 17:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.