I've just read this:
http://www.parashift.com/c++-faq-lit....html#faq-10.3
That is a new object intuitively, so I don't like this way even the
compiler really has special support for it.
Anyway thanks for your comment.
Alexander Dong Back Kim wrote:
> On Apr 15, 12:21 pm, Warren Tang <warren.c.t...@gmail.com> wrote:
>> Hello,
>>
>> Does C++ allow a constructor to call another constructor of the same
>> class? (I am focusing on the language abilities. I know the C# language
>> allow this.)
>>
>> The following sample can explain this question more clearer:
>>
>> class MyClass
>> {
>> public:
>> MyClass()
>> {
>> //Do something.
>> }
>> MyClass(int a, int b)
>> {
>> //I need to call the parameter-less constructor. How?
>> }
>>
>> Thank you for your attention.
>>
>> Regards
>> Warren
>
> Yes Absolute!
>
> int _a, _b;
>
> MyClass()
> {
> _a = 10;
> _b = 20;
> }
> MyClass(int a, int b)
> {
> _a = a;
> _b = b;
>
> MyClass(); // this->MyClass(); // more precisely
> }
>
> the result will be _a = 10, _b = 20 even you create an instance by
> calling
>
> MyClass * _pClass = new MyClass(100, 100);
>
> cheers,