+ 9
What is differences between private and constructor?
6 Respuestas
+ 5
Constructor is a special member function of the class which get automatically called on object creation.
While private section in c++ is used to declare and define variables,member fuctions which are accessible only within the class,not to any other class and main function as well.
+ 4
Seb TheS are you saying that all constructors are private?
+ 3
Constructor is a magic method, and magic methods are all private.
Private is only an attribute of a name, private members of a class:
Are not strictly accessible from outside from the class.
Will not be strictly inherited by the class' objects.
Will not be strictly inherited to the childclasses.
+ 2
Private in C# and some other languages is a way to make a method available or not to another method or object... a constructor, in C# is a method that runs, when you instantiate an object of a class. Example: there is this class named qwerty, and there is this method that is also named querty. Both of them are outside the Main class. In the main class, you can instantiate an object of the qwerty class, wich will also call the qwerty method(that is the constructor). This method will run first and than the class.
+ 1
Haha, 4 sure, that is not what Im saying. Im just saying they are two whole different things
0
Private is access specifier. Private data members can not accessible outside the class.
A constructor is a special member function of a class whose name is same as a class name and which is automatically called when an object is called.