-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask2.cpp
More file actions
43 lines (35 loc) · 1.03 KB
/
Copy pathTask2.cpp
File metadata and controls
43 lines (35 loc) · 1.03 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
#include <iostream>
#include <typeinfo>
#include <string>
#include <stdexcept>
#include <utility>
#include "AnyType.h"
int main() {
try {
AnyType anyType = 1;
anyType = true;
anyType = 1.7;
int storedValue = anyType.get<int>(); // Throws bad_cast exception
}
catch (const std::bad_cast& e) {
std::cout << "Bad cast exception: " << e.what() << std::endl;
}
try {
AnyType anyType = 1.7;
double storedValue = anyType.get<double>();
std::cout << "Stored double value: " << storedValue << std::endl;
}
catch (const std::bad_cast& e) {
std::cout << "Bad cast exception: " << e.what() << std::endl;
}
try {
AnyType anyType = 1.7;
double storedValue = anyType.get<float>();
std::cout << "Stored double value: " << storedValue << std::endl;
}
catch (const std::bad_cast& e) {
std::cout << "Bad cast exception: " << e.what() << std::endl;
}
AnyType anyType1 = 23, anyType2 = 1.5;
return 0;
}