-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
64 lines (56 loc) · 958 Bytes
/
Copy pathexample.cpp
File metadata and controls
64 lines (56 loc) · 958 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
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
#include "poly_variant.h"
#include <iostream>
class Shape
{
public:
virtual ~Shape() = default;
virtual void draw() = 0;
};
class Circle : public Shape
{
public:
void draw() override
{
std::cout << "Circle" << std::endl;
}
};
class Square : public Shape
{
public:
void draw() override
{
std::cout << "Square" << std::endl;
}
};
class Triangle : public Shape
{
public:
void draw() override
{
std::cout << "Triangle" << std::endl;
}
};
class NotShape
{
public:
void draw()
{
std::cout << "Not a shape" << std::endl;
}
};
int main()
{
poly_variant<Shape, Circle, Square, Triangle> shape;
shape = Circle();
shape->draw();
shape = Square();
shape->draw();
shape = Triangle();
shape->draw();
/**
* cannot do this:
* poly_variant<Shape, Circle, Square, Triangle, NotShape> shape;
* or this:
* shape = NotShape();
*/
}