-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path20_marks.cpp
51 lines (40 loc) · 962 Bytes
/
20_marks.cpp
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
// // Create a class Marks that have one member variable marks and one member function that will print marks. We know that we can access member functions using (.) dot operator. Now you need to overload (->) arrow operator to access that function.
// // Header files
#include <iostream>
// // use namespace
using namespace std;
// // define class Marks
class Marks
{
private:
// // instance memeber variable
int marks;
public:
// // constructors
Marks()
{
marks = 0;
}
Marks(int marks)
{
this->marks = marks;
}
// // instance member function to print marks
void printMarks()
{
cout << "\nMarks => " << marks;
}
// // overload member access operator (->)
Marks *operator->()
{
return this;
}
};
int main()
{
Marks m1(445); // create an object of Marks class
m1->printMarks();
cout << endl; // Add new line
cin.ignore();
return 0;
}