|
Thanks George,
The output is,
A
B
D
End.
But I do not know what do you want to prove? Any more descriptions please?
regards,
George
|
|
|
|
|
George_George wrote: I do not know what do you want to prove?
are you stupid ? you have the order of execution, so you can deduce from there the order in which the members are initialized...
|
|
|
|
|
perhaps a stronger example could be
...
public:
C() : b()
{
wcout << L"D\n";
}
...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
toxcct wrote: are you stupid ?
You're definitely unable to be patient with that guy!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
PATIENT ? WTF !!!
i've been waiting 1 year and a half for an answer to a question of mine, and you call me not patient ?
|
|
|
|
|
toxcct wrote: i've been waiting 1 year and a half for an answer to a question of mine, and you call me not patient ?
and did he eventually give it?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
eventually ?
have you ever seen that monkey replying to one of your questions ?
but you know, those chinese people (i mean, the ones living in china) have so much restrictions over their head by their governement that i wouldn't be astonished that they are feared to give too much personal informations.
anyway, i definitely know a good one about him : George_George is a prat, a moron, wait, A DICKHEAD !!
someone with a minimal common sense wouldn't reask same things again and again.
|
|
|
|
|
toxcct wrote: have you ever seen that monkey replying to one of your questions ?
Yes, he did.
I understand you're angry with him, but... be patient.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: Yes, he did.
where ? and about what ?
if it was about a technical question, yes, he will sometimes answer.
about personnal question, never. and not only he doesn't reply not really exactly, but he totally ignore us.
CPallini wrote: I understand you're angry with him, but... be patient.
as long as he continue in his direction, I have absolutely no reason to change my idea of this guy. it's up to him to show me a better side of his.
|
|
|
|
|
toxcct wrote: where ? and about what ?
I asked him what is the reason behind all his questions. He answered was just for technical fun.
toxcct wrote: I have absolutely no reason to change my idea of this guy
Oh, you don't have to. But I think you could just be more patient with him.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
toxcct wrote: it's up to him to show me a better side of his.
By telling you his age? How exactly does that matter to anything?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: By telling you his age?
Or if he comes from China?
Well I think toxcct is just a curious guy.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks toxcct,
I want to learn from you guys whether it is good code to leave some initialization of member variable code outside constructor, like I showed in the sample.
regards,
George
|
|
|
|
|
Change the order of A and B in the C class and see the result:
class C
{
B b;
A a;
public:
C() : a()
{
wcout << L"D\n";
}
};
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks George,
Will the initialization sequence impact the way we program, I mean, because of the sequence of initialization, what points do we need to consider in your experiences?
regards,
George
|
|
|
|
|
Yes, it does impact the way you write a class.
In addition to that, the rules for guaranteed object initialization to take place (By the way, I consider POD types objects too!) are complicated. Thus, I always initialize my objects before I use them. In a class, this is done in the initialization list in the order the member variables appear in the class. Using the initialization list is the most efficient technique. Avoid assignment whenever possible! Please note, however, that, with built-in types (POD types), there is no extra cost in using assignment over initialization but having consistant code is always a plus.
Our example code demonstrated the classes A and B were initialize with or without an initialization list in the order of appearance in class C. Placing theses classes in class C's initialization list might seem like overkill to you. However, by placing them in the initialization list, you erase any doubt about whether you classes have been properly initialized.
Finally, order of initialization due to placement of member variables can get a little tricky if a member variable requires other member variables to be initialized before its initialization. Thus, you have to order your member variables accordingly. If you cannot order your member variables due to a really complicated initialization dependency, you may have to uses other methods such as assignment in the constructor body.
I hope I was clear,
George
References:
[Meyers2005] Scott Meyers,Effective C++: 55 Specific Ways to Improve your Programs and Designs, Third edition, Addison-Wesley.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Thanks George!
Cool! My question is answered.
regards,
George
|
|
|
|
|
please, George, don't give too much to George_George. he's been abusing this board for several months, and he doesn't even search the web before asking very simple question.
so, please, don't give him too easy answers...
|
|
|
|
|
Toxcct,
I understand your pain, and have been following George_George exploits. He bites the hand that feeds him! However, my goal is to help and I won't let posters such as George_George change my focus just because he is a SOAB.
Geo
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
George L. Jackson wrote: just because he is a SOAB
lol, i feel lighter now that someone else have the same feeling than me.
BTW, I do have the same goal too, and I generally answer his technical questions, but there a time when he already has enough to find his answer. it's not our job to pound out a full working code. we are here to advice and to help when others are in real need. posting just to post is not my religion.
modified on Tuesday, December 18, 2007 10:33:26 AM
|
|
|
|
|
Sometimes, I get over helpful. However, I just modified his code a bit and asked him to play with the order of the member variables to lead him to his own Aha! moment. Of course, his post proved:
He was what I thought he was, and I let him off the hook.
Geo
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I agree a bit with you, but disagree too. Maybe is not "fair" to give him the easy answer, but for other users that maybe don't have had the "problem" or "question" before (i.e. me) an easy answer is full worthy to learn. Actually I have to say that altough GG is sometimes annoying, some of his questions had been interesting and the answers ave been very usefull for me to get some points that I hadn't even thought about.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
The compiler will give the class initialize implicitly.In the book "Inside the C++ Object Model", it detailed specifically.
Later buggers harm more.
|
|
|
|
|
Hi
I need to make the header font bold in my ListControl. How do I do that?? Whihc message should I handle?? I dont see any variable in the NMLVCUSTOMDRAW structure for doing this. Please help
With Reagards
Vikas
|
|
|
|
|
Hello,
I have declared a namespace for 3 of my classes and changed the declarations accordingly using : : but I don’t know how to change the declarations of message maps.
In the following I get error saying
Dialog::OnCreate' : member from enclosing class is not a type name, static, or enumerator
error C2065: 'OnCreate' : undeclared identifier
error C2440: 'type cast' : cannot convert from 'int *' to 'int (__thiscall CWnd::*)(struct tagCREATESTRUCTA *)'
BEGIN_MESSAGE_MAP(f::Dialog, CDialog)
//{{AFX_MSG_MAP(CDynDialogEx)
ON_WM_CREATE()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_HELP, OnHelpMsg)
ON_WM_MEASUREITEM()
ON_WM_DRAWITEM()
In the above OnCreate() is the message handler function
Prithaa
|
|
|
|