Click here to Skip to main content
15,891,431 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
jschell1-May-24 13:09
jschell1-May-24 13:09 
AnswerRe: change exe icon not work with multiple stage icon file. Pin
CPallini2-May-24 4:07
mveCPallini2-May-24 4:07 
GeneralRe: change exe icon not work with multiple stage icon file. Pin
Dave Kreskowiak2-May-24 4:11
mveDave Kreskowiak2-May-24 4:11 
GeneralRe: change exe icon not work with multiple stage icon file. Pin
CPallini2-May-24 4:14
mveCPallini2-May-24 4:14 
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 
GeneralNavigating thru debug messages using C++ code Pin
Salvatore Terress3-May-24 4:08
Salvatore Terress3-May-24 4:08 
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 Terress23hrs 20mins ago
Salvatore Terress23hrs 20mins ago 
GeneralRe: Navigating thru debug messages using C++ code Pin
Victor Nijegorodov18hrs 28mins ago
Victor Nijegorodov18hrs 28mins ago 
GeneralRe: Navigating thru debug messages using C++ code Pin
Richard MacCutchan7hrs 49mins ago
mveRichard MacCutchan7hrs 49mins ago 
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

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.