forked from JiauZhang/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstantiate_class.cpp
More file actions
89 lines (75 loc) · 2.08 KB
/
Copy pathinstantiate_class.cpp
File metadata and controls
89 lines (75 loc) · 2.08 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream>
#include <cassert>
#include <string>
#include <vector>
#include <map>
using namespace std;
//template <typename T>
class SolverParameter
{
public:
SolverParameter() {cout << "SolverParameter constructor" << endl;}
};
template <typename T>
class SolverRegistry
{
public:
SolverRegistry(const string& type, int* (*creator)(const SolverParameter&));
static void AddCreator(const string& type, int* (*creator)(const SolverParameter&))
{
cout << "AddCreator" << endl;
}
};
template <typename T>
class SolverRegisterer
{
public:
SolverRegisterer(const string& type, int* (*creator)(const SolverParameter&));
};
// Instantiate a class with float and double specifications.
#define INSTANTIATE_CLASS(classname) \
char gInstantiationGuard##classname; \
template class classname<float>; \
template class classname<double>
template <typename Dtype>
SolverRegisterer<Dtype>::SolverRegisterer(
const string& type, int* (*creator)(const SolverParameter&)) {
SolverRegistry<Dtype>::AddCreator(type, creator);
cout << "SolverRegisterer constructor" << endl;
}
INSTANTIATE_CLASS(SolverRegistry);
INSTANTIATE_CLASS(SolverRegisterer);
int *test_func(const SolverParameter&)
{
cout << test_func << endl;
int *test_int = new int;
}
class private_class
{
public:
int count;
//static int count;
//static int static_int;
//static º¯ÊýÖв»¿ÉÔÙÓÃstatic±äÁ¿ÁË
static private_class &get_private_class() {
static private_class *private_class_ = new private_class;
//cout << "count = " << (*private_class_).count << endl;
cout << "count = " << private_class_->count++ << endl;
//private_class::count++;
//(*private_class_).count++;
return *private_class_;
}
private:
private_class(): count(0){
cout << "private_class" << endl;
}
};
int main(int argc, char **argv)
{
class SolverRegisterer<float> test("alsd", test_func);
private_class::get_private_class();
private_class::get_private_class();
private_class::get_private_class();
private_class::get_private_class();
return 0;
}