Click here to Skip to main content
15,895,142 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: allocate memory Pin
Youming Lee27-Sep-11 4:12
Youming Lee27-Sep-11 4:12 
GeneralRe: allocate memory Pin
Code-o-mat27-Sep-11 4:26
Code-o-mat27-Sep-11 4:26 
AnswerRe: allocate memory Pin
Erudite_Eric27-Sep-11 3:37
Erudite_Eric27-Sep-11 3:37 
Questionmap of map in c++ Pin
002comp27-Sep-11 0:25
002comp27-Sep-11 0:25 
AnswerRe: map of map in c++ Pin
Code-o-mat27-Sep-11 1:31
Code-o-mat27-Sep-11 1:31 
GeneralRe: map of map in c++ Pin
Stefan_Lang28-Sep-11 1:12
Stefan_Lang28-Sep-11 1:12 
GeneralRe: map of map in c++ Pin
Code-o-mat28-Sep-11 1:37
Code-o-mat28-Sep-11 1:37 
AnswerRe: map of map in c++ Pin
Stefan_Lang27-Sep-11 5:43
Stefan_Lang27-Sep-11 5:43 
Use the correct data structures! Nothing in the code and explanations you gave warrants the use of a map, let alone a map of maps. For all I know a simple C-style array might suffice, or maybe a std::vector, if you have need to add or remove elements after the intial construction of that array.

Besides, I understand that the code you provided just serves as an illustration of your problem, not as real code, but none of the member variables in your classes can be accessed - they are all private and you have no accessor functions!

For sake of simplicity I changed the classes A and Apart to struct. The following should serve your purposes at least so far as you have described them:
C++
struct Apart { // declare the basic structs before the compounds!
   std::string c; // *see below
   std::string d;
   int a;
   int b;
};
struct A {
   int id;
   std::string a;
   std::string b;
   int nparts;   // to store the size of the array below
   Apart* parts; // array of parts
};
void initializeA(A& myA, int number_of_parts) {
   myA.nparts = 0; // in case something goes wrong
   if (myA.parts = new Apart[number_of_parts]) {
      myA.nparts = number_of_parts;
      // do any further initialization if needed
   }
}

* Note: I prefer to not add using statements to my code. there are way too many libraries for similar things, and often the names used within the namespaces of these libraries are very simple and might easily clash with existing symbols, or symbols from other libraries. Therefore I prefer std::string over just string. It has the added advantage that code posted into a forum out of context can be easily recognized to be using a specific library, in this case the STL.
QuestionIs it possible to suspend a thread when the thread has executed Sleep() statement and in sleep mode Pin
manoharbalu27-Sep-11 0:14
manoharbalu27-Sep-11 0:14 
AnswerRe: Is it possible to suspend a thread when it executes Sleep() statement Pin
Software_Developer27-Sep-11 0:59
Software_Developer27-Sep-11 0:59 
GeneralRe: Is it possible to suspend a thread when the thread executes Sleep() statement Pin
manoharbalu27-Sep-11 1:01
manoharbalu27-Sep-11 1:01 
AnswerRe: Is it possible to suspend a thread when it executes Sleep() statement [link fixed, thanks to Chris] Pin
CPallini27-Sep-11 1:02
mveCPallini27-Sep-11 1:02 
GeneralRe: Is it possible to suspend a thread when it executes Sleep() statement Pin
Chris Meech27-Sep-11 2:36
Chris Meech27-Sep-11 2:36 
GeneralRe: Is it possible to suspend a thread when it executes Sleep() statement Pin
CPallini27-Sep-11 2:52
mveCPallini27-Sep-11 2:52 
AnswerRe: Is it possible to suspend a thread when the thread has executed Sleep() statement and in sleep mode Pin
David Crow27-Sep-11 15:57
David Crow27-Sep-11 15:57 
Question[MFC] Keep thread alive until application exits Pin
Erik26-Sep-11 23:39
Erik26-Sep-11 23:39 
AnswerRe: [MFC] Keep thread alive until application exits Pin
Erudite_Eric26-Sep-11 23:43
Erudite_Eric26-Sep-11 23:43 
GeneralRe: [MFC] Keep thread alive until application exits Pin
Albert Holguin27-Sep-11 4:46
professionalAlbert Holguin27-Sep-11 4:46 
GeneralRe: [MFC] Keep thread alive until application exits Pin
Rajesh R Subramanian27-Sep-11 7:26
professionalRajesh R Subramanian27-Sep-11 7:26 
GeneralRe: [MFC] Keep thread alive until application exits Pin
Albert Holguin27-Sep-11 7:30
professionalAlbert Holguin27-Sep-11 7:30 
GeneralRe: [MFC] Keep thread alive until application exits Pin
Albert Holguin27-Sep-11 7:35
professionalAlbert Holguin27-Sep-11 7:35 
AnswerRe: [MFC] Keep thread alive until application exits Pin
Chuck O'Toole27-Sep-11 4:11
Chuck O'Toole27-Sep-11 4:11 
GeneralRe: [MFC] Keep thread alive until application exits Pin
Albert Holguin27-Sep-11 7:51
professionalAlbert Holguin27-Sep-11 7:51 
GeneralRe: [MFC] Keep thread alive until application exits Pin
Chuck O'Toole27-Sep-11 8:38
Chuck O'Toole27-Sep-11 8:38 
GeneralRe: [MFC] Keep thread alive until application exits Pin
Albert Holguin27-Sep-11 9:24
professionalAlbert Holguin27-Sep-11 9:24 

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.