-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstr1
More file actions
68 lines (47 loc) · 1.28 KB
/
Copy pathConstr1
File metadata and controls
68 lines (47 loc) · 1.28 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
using namespace std;
/*
A simple codes that can help you
understanding about constructor
*/
class myClass
{
private:
string name;
public:
void setname(string x)
{
name = x;
}
string getname()
{
return name;
}
// An example for constructor
///////////////////////////////////////////////
myClass(string y) // Constructor..
{
setname(y); // call function setname();
cout << "Hello, i'am your classmates, " << getname() << "\n\n";
}
/*
Syntax:
className(parameter)
{
some codes......
}
Constructor name is must same as the class name...
*/
///////////////////////////////////////////////
};// dont forgot to put semicolon
int main()
{
myClass mizuki("Mizuki..");
myClass bean("Bean..");
myClass andy("Andy..");
/*
After we make a constructors as before, we doesn't need making a "cout (hello, i am your...), setname, getname" for every person (Mizuki,Bean,Andy) on myClass.
It will executed the constructors codes automatically on every object or person we made on myClass as before.
*/
return 0;
}