-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber.cpp
More file actions
32 lines (26 loc) · 752 Bytes
/
number.cpp
File metadata and controls
32 lines (26 loc) · 752 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
#include <iostream>
class Number {
private:
int value;
public:
// Constructor
Number(unsigned long int v) : value(v) {}
// Overloading the dereference operator to allow direct access to the value
int& operator*() {
return value; // Return reference to the value
}
// Overloading the assignment operator if needed (optional but good practice)
Number& operator=(const int& v) {
value = v;
return *this;
}
// You can also overload other operators as needed, for example, the increment operator
Number& operator++() {
++value;
return *this;
}
// Optional: To print the value easily
void print() const {
std::cout << value << std::endl;
}
};