Eiffel "creates" over C ++ constructor?

What is the difference between the C ++ constructor and the declaration of the procedure for creating Eiffels?

What is the importance of being able to have several constructor functions for a class? Or is there any other use for Eiffel to β€œcreate”?

Thankyou

+4
source share
1 answer

In C ++, you can overload constructors, so you can also define multiple constructors.

Having constructor procedures, as in EIFFEL, has the advantage that you can define different constructors that have the same signature (the same number and type of arguments).

Imagine the Triangle class: you can build a triangle by specifying the lengths of three sides (three values ​​of the float) or by giving two sides and a covering angle (also three values ​​of the float).

In C ++ you will need to define an additional parameter (for example, the enum value for the "build mode"), in EIFFEL you can simply define two build procedures with different names.

+3
source

Source: https://habr.com/ru/post/1390896/


All Articles