You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// // Create an Integer class that contains int x as an instance variable and overload casting int() operator that will type cast your Integer class object to int data type.
2
+
3
+
// // Header files
4
+
#include<iostream>
5
+
#include<conio.h>
6
+
7
+
// // use namespace
8
+
usingnamespacestd;
9
+
10
+
// // define class Integer
11
+
classInteger
12
+
{
13
+
private:
14
+
// // instance memeber variable
15
+
int value;
16
+
17
+
public:
18
+
// // Constructor
19
+
Integer()
20
+
{
21
+
value = 0;
22
+
}
23
+
24
+
Integer(int val)
25
+
{
26
+
value = val;
27
+
}
28
+
29
+
// // instance memebr function to get value
30
+
voidsetValue(int val)
31
+
{
32
+
value = val;
33
+
}
34
+
35
+
// // instance memebr function to get value
36
+
intgetValue()
37
+
{
38
+
return value;
39
+
}
40
+
41
+
// overload logical NOT (!) operator
42
+
operatorint()
43
+
{
44
+
return value;
45
+
}
46
+
};
47
+
48
+
intmain()
49
+
{
50
+
int val;
51
+
cout << "\nEnter A Number => ";
52
+
cin >> val;
53
+
54
+
Integer num1(val); // create an object of Integer class
0 commit comments