-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructors.cpp
More file actions
38 lines (30 loc) · 868 Bytes
/
constructors.cpp
File metadata and controls
38 lines (30 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// ********constructor***************
#include <iostream>
using namespace std;
class complex{
private: int a,b;
public:
// creating a constructor
// Constructor is a special member function with the same name as of the
// class. It is automatically invoked
// It is used to initialize the objects of its class
complex(void);
void printnum(){
cout<<"yout number is "<< a <<" + "<< b <<"i"<<endl;
}
};
complex :: complex(void){
a=10;
b=0;
}
int main(){
complex c;
c.printnum();
return 0;
}
// *******properties of constructors ********
// 1.constructors is always defined in public sector of class
// 2.They are automatically invoked whenver the object is created
// 3.They cannot return values and do not have return types
// 4.It can have default arguments
// 5.We can not refer to their address