Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use cases for two-phase initialization

Tags:

c++

oop

I've seen a lot of two-phase initialization used. The justification is to call virtual functions from the secondary constructor. However, I've never, ever, seen any use case in which this was necessary. Are there any?

like image 846
Puppy Avatar asked Sep 29 '12 14:09

Puppy


1 Answers

On platforms where there is no support for exceptions, or the code size increase due to exception handling is unacceptable, two-phase initialization allows you to put activities that might fail in the secondary constructor.

like image 71
combinatorial Avatar answered Oct 20 '22 01:10

combinatorial