-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.cpp
42 lines (30 loc) · 833 Bytes
/
example.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
36
37
38
39
40
41
42
#include <iostream>
#include "property.hpp"
class A {
private:
int i_ = 5;
int get_i() const { return i_; }
void set_i(int new_i) {
if (new_i < 0 || new_i > 10) return;
i_ = new_i;
}
float get_f() const { return 50.f; }
public:
A(){}; // note: default constructor required for MSVC
// A() = default; // will fail to link under MSVC
PROPERTIES_BEGIN()
fcp::property<int, &A::get_i, &A::set_i> i;
fcp::property<float, &A::get_f> f;
PROPERTIES_END()
};
int main() {
A a{};
auto a2 = a;
a.i = 6;
std::cout << "a.i: " << a.i << "\n"; // prints 6
a.i = 20;
std::cout << "a.i: " << a.i << "\n"; // prints 6
// auto error = a.i; // will not compile
// a.f = 7.f; // fails to compile
std::cout << "a.f: " << a.f << "\n"; // prints 50
}