Click here to Skip to main content
15,906,335 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Navigating thru debug messages using C++ code Pin
Victor Nijegorodov3-May-24 4:13
Victor Nijegorodov3-May-24 4:13 
GeneralRe: Navigating thru debug messages using C++ code Pin
Salvatore Terress3-May-24 6:49
Salvatore Terress3-May-24 6:49 
GeneralRe: Navigating thru debug messages using C++ code Pin
Victor Nijegorodov3-May-24 11:41
Victor Nijegorodov3-May-24 11:41 
GeneralRe: Navigating thru debug messages using C++ code Pin
Richard MacCutchan3-May-24 22:20
mveRichard MacCutchan3-May-24 22:20 
QuestionObjects hierarchy ? Pin
Salvatore Terress29-Apr-24 5:15
Salvatore Terress29-Apr-24 5:15 
AnswerRe: Objects hierarchy ? Pin
Richard MacCutchan29-Apr-24 6:29
mveRichard MacCutchan29-Apr-24 6:29 
QuestionHow to track "nested objects "? Pin
Salvatore Terress18-Apr-24 8:34
Salvatore Terress18-Apr-24 8:34 
AnswerRe: How to track "nested objects "? Pin
Mircea Neacsu18-Apr-24 9:13
Mircea Neacsu18-Apr-24 9:13 
I assume your question is about the order of initialization of compound objects.

C++
#include <iostream>
using std::cout;

class level3 {
public:
  level3(const std::string& name);
};

class level2 {
public:
  level2(const std::string& name);

private:
  level3 grandchild;
  level3 favourite_grandchild;
};

class top_level {
public:
  top_level(const std::string& name);

private:
  level2 child;
  level2 other_child;
};

top_level::top_level(const std::string& name)
  : other_child("other_child") //this will be called AFTER initialization of 'child'
  , child("child")         //this is called first because 'child' is declared first
{
  cout << name << " constructor\n";
}

level2::level2(const std::string& name)
  : favourite_grandchild("favourite_grandchild") //this is again called AFTER the next line
  , grandchild("grandchild")                     //this is called first
{
  cout << name << " level2 constructor\n";
}

level3::level3(const std::string& name)
{
  cout << name << " level3 constructor\n";
}

int main()
{
  top_level t("top");
}


The result is this:
grandchild level3 constructor
favourite_grandchild level3 constructor
child level2 constructor
grandchild level3 constructor
favourite_grandchild level3 constructor
other_child level2 constructor
top constructor


In words: aggregate objects initialize their members in the order in which the members are declared, not in the order of initializers in the constructor of the aggregate. After initializing all members, the constructor code is run.
Mircea

GeneralRe: How to track "nested objects "? Pin
Salvatore Terress18-Apr-24 14:57
Salvatore Terress18-Apr-24 14:57 
GeneralRe: How to track "nested objects "? Pin
Salvatore Terress19-Apr-24 4:00
Salvatore Terress19-Apr-24 4:00 
GeneralRe: How to track "nested objects "? Pin
Mircea Neacsu19-Apr-24 4:31
Mircea Neacsu19-Apr-24 4:31 
GeneralRe: How to track "nested objects "? Pin
Salvatore Terress19-Apr-24 7:11
Salvatore Terress19-Apr-24 7:11 
GeneralRe: How to track "nested objects "? Pin
Mircea Neacsu19-Apr-24 7:43
Mircea Neacsu19-Apr-24 7:43 
GeneralRe: How to track "nested objects "? Pin
k505419-Apr-24 8:16
mvek505419-Apr-24 8:16 
GeneralRe: How to track "nested objects "? Pin
Salvatore Terress19-Apr-24 9:48
Salvatore Terress19-Apr-24 9:48 
GeneralRe: How to track "nested objects "? Pin
k505419-Apr-24 10:58
mvek505419-Apr-24 10:58 
GeneralRe: How to track "nested objects "? Pin
Salvatore Terress20-Apr-24 15:38
Salvatore Terress20-Apr-24 15:38 
GeneralRe: How to track "nested objects "? Pin
Richard MacCutchan21-Apr-24 2:04
mveRichard MacCutchan21-Apr-24 2:04 
AnswerRe: How to track "nested objects "? Pin
Maximilien19-Apr-24 4:13
Maximilien19-Apr-24 4:13 
GeneralRe: How to track "nested objects "? Pin
Salvatore Terress19-Apr-24 14:01
Salvatore Terress19-Apr-24 14:01 
AnswerRe: How to track "nested objects "? Pin
Richard MacCutchan19-Apr-24 6:32
mveRichard MacCutchan19-Apr-24 6:32 
QuestionCan a locale be Removed from a basic_ostream Subsequent to basic_ostream.imbue(locale) Pin
BernardIE531717-Apr-24 1:48
BernardIE531717-Apr-24 1:48 
AnswerRe: Can a locale be Removed from a basic_ostream Subsequent to basic_ostream.imbue(locale) Pin
Mircea Neacsu17-Apr-24 2:03
Mircea Neacsu17-Apr-24 2:03 
GeneralRe: Can a locale be Removed from a basic_ostream Subsequent to basic_ostream.imbue(locale) Pin
BernardIE531717-Apr-24 11:55
BernardIE531717-Apr-24 11:55 
GeneralRe: Can a locale be Removed from a basic_ostream Subsequent to basic_ostream.imbue(locale) Pin
Mircea Neacsu17-Apr-24 12:14
Mircea Neacsu17-Apr-24 12:14 

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.