Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

about [Inside The C++ Object Model]

1 view
Skip to first unread message

jason chen

unread,
Oct 31, 2009, 3:23:40 AM10/31/09
to
hello:
A stupid question like this:
when I read the [Inside the C++ object model], I meet a question.
"You must use the member initialization list, when you call the constructo
of a member class, and it provided with some parameters."
I can't understand it.
Anybody can answer me? Thank you very much

--
Jason
Thanks and Best Regards!


Paavo Helde

unread,
Oct 31, 2009, 4:40:50 AM10/31/09
to
"jason chen" <chenxi...@163.com> wrote in
news:hcgolt$m1q$1...@www.shinco.com:

> hello:
> A stupid question like this:
> when I read the [Inside the C++ object model], I meet a question.
> "You must use the member initialization list, when you call the
> constructo
> of a member class, and it provided with some parameters."
> I can't understand it.
> Anybody can answer me? Thank you very much

The wording is not very clear, but I think this basically means that line
(1) below won't compile, but (2) compiles:

class A {
public:
A(int) {}
};

class B {
A a;
public:
B() {a=1;} // (1) - wrong
B(): a(1) {} // (2) - right
};

There is also a FAQ on that topic:

http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.6

hth
Paavo

jason chen

unread,
Oct 31, 2009, 5:38:10 AM10/31/09
to
I see.
Thank your very much.

--
Jason
Thanks and Best Regards!

"Paavo Helde" <myfir...@osa.pri.ee> д����Ϣ����:Xns9CB56CA9B...@216.196.109.131...

Fraser Ross

unread,
Oct 31, 2009, 11:00:29 AM10/31/09
to
The default constructor would be invoked for members that aren't in the
initialiser list. There isn't another option.

Fraser.


0 new messages