-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut29.cpp
More file actions
40 lines (32 loc) · 901 Bytes
/
tut29.cpp
File metadata and controls
40 lines (32 loc) · 901 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
39
40
#include <iostream>
using namespace std;
class complex
{
int a , b ;
public :
// Creating a Constructor
// Constructor is a special member function with the same name as of the class.
//It is used to initialize the objects of its class
//It is automatically invoked whenever an object is created
complex(void);
void printnum(){
cout<<"The number is "<< a<<" and "<< b <<endl;
}
};
complex :: complex(){ //----> This is a default constructor as it takes no parameters
a = 10 ;
b = 5 ;
}
int main ()
{
complex c1 ;
c1.printnum();
return 0 ;
}
/* characteristics of constructor
1. It should be declared in the public secton of the class
2. They are automatically invoked whenever the object is created
3. They can not return valued and not have return types
4. It can have default arguement
5. we can not refer to their address
*/