-
Notifications
You must be signed in to change notification settings - Fork 962
/
Copy pathclass1.h
65 lines (57 loc) · 1.51 KB
/
class1.h
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
#pragma once
#include <Windows.h>
namespace cx_properties
{
public ref class Class1 sealed
{
public:
Class1();
};
//<snippet01>
public ref class Prescription sealed
{
private:
Platform::String^ m_doctor;
int quantity;
public:
Prescription(Platform::String^ name, Platform::String^ d) : m_doctor(d)
{
// Trivial properties can't be initialized in member list.
Name = name;
}
// Trivial property
property Platform::String^ Name;
// Read-only property
property Platform::String^ Doctor
{
Platform::String^ get() { return m_doctor; }
}
// Read-write property
property int Quantity
{
int get() { return quantity; }
void set(int value)
{
if (value <= 0)
{
throw ref new Platform::InvalidArgumentException();
}
quantity = value;
}
}
};
public ref class PropertyConsumer sealed
{
private:
void GetPrescriptions()
{
Prescription^ p = ref new Prescription("Louis", "Dr. Who");
p->Quantity = 5;
Platform::String^ s = p->Doctor;
int32 i = p->Quantity;
Prescription p2("JR", "Dr. Dat");
p2.Quantity = 10;
}
};
//</snippet01>
}