Click here to Skip to main content
15,890,282 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
PinnedHOW TO ANSWER A QUESTION PinPopular
Chris Maunder12-Jul-09 22:37
cofounderChris Maunder12-Jul-09 22:37 
PinnedHOW TO ASK A QUESTION PinPopular
Chris Maunder12-Feb-09 17:19
cofounderChris Maunder12-Feb-09 17:19 
Questionchange exe icon not work with multiple stage icon file. Pin
Le@rner1-May-24 2:26
Le@rner1-May-24 2:26 
AnswerRe: change exe icon not work with multiple stage icon file. Pin
Victor Nijegorodov1-May-24 4:21
Victor Nijegorodov1-May-24 4:21 
GeneralRe: change exe icon not work with multiple stage icon file. Pin
jschell17hrs 37mins ago
jschell17hrs 37mins ago 
AnswerRe: change exe icon not work with multiple stage icon file. Pin
CPallini2hrs 39mins ago
mveCPallini2hrs 39mins ago 
GeneralRe: change exe icon not work with multiple stage icon file. Pin
Dave Kreskowiak2hrs 35mins ago
mveDave Kreskowiak2hrs 35mins ago 
GeneralRe: change exe icon not work with multiple stage icon file. Pin
CPallini2hrs 32mins ago
mveCPallini2hrs 32mins ago 
QuestionSOLVED Posting "debug (window ) view ? Pin
Salvatore Terress30-Apr-24 2:51
Salvatore Terress30-Apr-24 2:51 
AnswerRe: Posting "debug (window ) view ? Pin
Maximilien30-Apr-24 2:56
Maximilien30-Apr-24 2:56 
AnswerRe: Posting "debug (window ) view ? Pin
Victor Nijegorodov30-Apr-24 3:40
Victor Nijegorodov30-Apr-24 3:40 
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 
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 
If you have an object like this:
C++
class Thing1 {
public:
  Thing1 ();
}
You can use it in another object:
C++
class Composite {
public:
  Composite ();
private:
  Thing1* part;
};

Composite::Composite()
  : part (new Thing1)
{
}
In Composite, the member part is a pointer to a Thing1. When a composite is constructed, first the program allocates on heap a new object of type Thing1 and invokes it constructor. Because constructor for Thing1 does not have any parameters there is no need for a list of parameters.

Next step:
You have another type of object Thing2 declared like:
C++
class Thing2 {
public:
  Thing2 (int param=42);
};
and the Composite object has 2 members:
C++
class Composite {
public:
  Composite ();
private:
  Thing1* part;
  Thing2* other_part;
};
The constructor of Composite could be:
C++
Composite::Composite ()
  : part (new Thing1) //as before
  , other_part (new Thing2) //same as saying other_part(new Thing2(42))
{}
because now the constructor for Thing1 needs a parameter but the parameter has a default value and the compiler will call the constructor with said value. Obviously, if you need a different value for the parameter, you will have to add it:
C++
Composite::Composite ()
  : part (new Thing1) //as before
  , other_part (new Thing2(24) //explicit constructor parameter
{}


Going back to the original question (which you seem to have deleted)
What you want to have is it something like:
C++
class Composite{
public:
  Composite ();
private:
  Thing1 *part;
  Thing1 *other_part;
{}
? Try to rephrase your question it terms of simple objects to make it easier for us to understand.
Mircea

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 

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.