-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingelton.cpp
More file actions
30 lines (24 loc) · 814 Bytes
/
Copy pathsingelton.cpp
File metadata and controls
30 lines (24 loc) · 814 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
#include<iostream>
class Random {
public:
// Delete the copy constructor
Random (const Random&) = delete;
// Create a static get method that returns a static instance of the class
static Random& Get() {
static Random instance;
return instance;
}
// Static methods that calls the internal methods using the static instance returned by the Get method
static float Float() {return Get().IFloat();}
private:
// Actual implementaion of the static members, these methods can access
// the member functions
float IFloat () {return m_Number;}
// Make the constructor private to prevent creation of new instance of the class
Random() {}
// other members
float m_Number = 0.5f;
};
int main() {
std::cout << Random::Float() << std::endl;
}