forked from Mq-b/Loser-HomeWork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mq卢瑟.cxx
29 lines (28 loc) · 751 Bytes
/
mq卢瑟.cxx
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
#include<iostream>
class ComponentBase {
protected:
static inline std::size_t component_type_count = 0;
};
template<typename T>
class Component : public ComponentBase {
public:
static std::size_t component_type_id() {
static std::size_t id = component_type_count++;
return id;
}
};
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;
}