Are there any issues with allocating memory within constructor initialization lists?

前端 未结 7 922
后悔当初
后悔当初 2020-12-05 10:50

I have used initialization lists a great deal in my C++ programs but wasn\'t aware that you could allocate memory within them.

So you can do something (as a contrive

7条回答
  •  盖世英雄少女心
    2020-12-05 11:26

    This code could leak memory in the presence of an initializer that throws an exception.

    Note that this could be made to work correctly if the members of Test were smart -- rather than raw -- pointers.

提交回复
热议问题