Eiffel "create" over C++ constructor?

378 views Asked by At

What is the difference between C++'s constructor and Eiffels create procedure declaration?

What value is there in being able to have multiple constructor functions for a class? Or is there any other benefit to Eiffels "create"?

Thankyou

1

There are 1 answers

6
MartinStettner On BEST ANSWER

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

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

Just imagine a Triangle class: You might want to construct a triangle by giving the lengths of the three sides (three float values), or by giving two sides and the enclosing angle (also three float values).

In C++ you would have to define an additional parameter (e.g. a enum value for the 'construction mode'), in EIFFEL you can simply define two construction procedures with different names.