Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top