c ++结构体构造函数
Constructors in C++ or any other language are a member function of a class that is used to initialize the newly created objects.
C ++或任何其他语言的构造函数是用于初始化新创建的对象的类的成员函数。
They have the same name as that of the class and do not return any value.
它们具有与类相同的名称,并且不返回任何值 。
Working of Constructors:
施工人员的工作:
As soon as the compiler encounters a newly created object, it invokes the constructor of the corresponding class automatically.
编译器一旦遇到新创建的对象,就会自动调用相应类的构造函数。
Then, the constructor initializes the newly created object of the class.
然后,构造函数初始化该类的新创建的对象。
C ++中的构造函数类型 (Types of Constructors in C++)
Following are the types of Constructors in C++:
以下是C ++中构造函数的类型:
- Default Constructors 默认构造函数
- Parameterized Constructors 参数化构造函数
- Copy Constructors <