forked from Mq-b/Loser-HomeWork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jacky.cpp
35 lines (29 loc) · 758 Bytes
/
jacky.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
#include <iostream>
class ComponentBase {
protected:
static inline size_t component_type_count = 0;
};
template <typename T>
class Component : public ComponentBase {
public:
inline static size_t myID = component_type_count++;
static size_t component_type_id()
{
return myID;
}
};
class A : public Component<A> {
};
class B : public Component<B> {
};
class C : public Component<C> {
};
int main()
{
std::cout << A::component_type_id() << std::endl;
std::cout << B::component_type_id() << std::endl;
std::cout << B::component_type_id() << std::endl;
std::cout << A::component_type_id() << std::endl;
std::cout << A::component_type_id() << std::endl;
std::cout << C::component_type_id() << std::endl;
}