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

前端 未结 7 902
后悔当初
后悔当初 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.

    0 讨论(0)
提交回复
热议问题