Sign in to follow this  
nGamer

Constructors in a composite class

Recommended Posts

nGamer    184
What's up GameDevers, If a class has other classes as data member, when that class's constructor is invoked, are the constructors of the classes that belong to it invoked as well?

Share this post


Link to post
Share on other sites
SiCrane    11839
For a class A, the constructors of all A's member variables will be called before execution flow will enter the first curly brace any of A's constructors.

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by mrchrismnh
seriously?
Why not clarify, so that we can better understand what you're getting at?

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by mrchrismnh
I mean does he really not understand what I am saying, or is he chiding me for not being precise about it. I suspect the latter.
I have a pretty good guess as to what you're trying to say, but it's just that (a guess).

Really, how hard would it be to give an example, or go into just a little more detail so that there's no ambiguity?

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by mrchrismnh
myclass* a;


is not going to construct, and neither will any of its member classes, until you call


a = new myclass;


or something similar
I'm not sure if you mean for a to be a member of the class in question or to point to the object that's being constructed, but in either case, your example doesn't introduce any exceptions or special cases as far as the OP's question is concerned.

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Oh lawd a mercy.
Hm. Honestly, I'm not really clear as to what your objection is. The questions that have been asked and the points that have been made all seem pretty reasonable.

If you feel otherwise, why not post something meaningful explaining your views? As is, it's not very clear what you're trying to say.

Share this post


Link to post
Share on other sites
bobofjoe    322
Technically; myclass * a; does initialize an instance of myclass *, as expected. I think you're confusing the types of an object and a pointer to an object, which are totally distinct.

Share this post


Link to post
Share on other sites
Sneftel    1788
Quote:
Original post by mrchrismnh
I already apologized for posting.

Goddamn, son. You just don't switch off, do you?

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by mrchrismnh
I think some people may be a little too impressed with themselves.
I know I shouldn't take the bait, but I think you're reading way too much into this thread.

It's a simple fact that if you post something inaccurate or unclear on a technical forum such as this one, it will likely be questioned or corrected. It's happened to me, and I'd venture to say it's happened at one time or another to most of the people who post here with any regularity (with a few possible exceptions ;).

In any case, there's really no point in getting bent out of shape about it.

Share this post


Link to post
Share on other sites
Nypyren    12074
He's not trolling, he's just a bit shocked that you guys have taken it to this level. Unfortunately the safest way to deal with people not understanding what you're trying to say, or taking issue with minor ambiguity on this forum is to NOT keep replying.

It's quite similar with grammar naziism in English. It's not productive to get in an argument about simple oversight.

I read his first post and immediately knew what he was talking about. I wager that anyone familiar enough with C++ to ask about composite construction would understand pretty quickly, too.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this