0
Is it really necessary for the constructor to have the same name as the class?
0
Is it really necessary for the constructor to have the same name as the class?
3
Yes, it is. Language requires it by convention. It might not be, but it is so.
Documentation. Also. Microsoft documentation. If the specification were published openly I would post here, but the excerpt from item 12.1 would be:
Constructors do not have Names. A special declarator syntax is used to declare or define the constructor.
So this is the syntax adopted by convention, although formally it doesn’t have an official name.
This goes for all languages I know that have the constructor mechanism.
0
Basically it’s the method called when you build that object, in the example
Cliente cliente = new Cliente();
the new
calls the constructor of the Customer class, constructing the desired object and assigning the variable. The use in this way is a convention believe, the visibility is better. In javascript use the word constructor
and in PHP __construct
as the class builder, showing that it is not a standardized thing for all.
Browser other questions tagged c++ oop characteristic-language builder
You are not signed in. Login or sign up in order to post.
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.
– Maniero