-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo4.cpp
72 lines (56 loc) · 1.11 KB
/
demo4.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
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
#include <iostream>
#include <string>
using namespace std;
class Screen; // 类声明
class LinkScreen // 到这里,LinkScreen类已声明
{
Screen *window;
LinkScreen *next; // 可定义类LinkScreen的指针,但不可定义LinkScreen对象。
LinkScreen *prev;
};
class Y;
class X
{
private:
Y *ptr;
};
class Y
{
private:
X *ptr;
X obj;
};
// 记录
class Record
{
public:
typedef size_t size;
Record(): byte_count(0){}
Record(size s): byte_count(s){}
Record(string s): name(s), byte_count(0){}
size get_count() const { return byte_count; }
string get_name() const { return name; }
private:
size byte_count;
string name; // 记录名称
};
struct Person
{
public:
Person(const string &nm, const string &addr): name(nm), address(addr){}
string getName() const { return name; }
string getAddress() const { return address; }
private:
string name;
string address;
};
int main()
{
X x;
Record r; // 在堆栈上创建类的对象。
class Record r2; // 传统C语言写法
Person pp("ha", "ha");
Record *p = new Record; // 在堆上动态地创建对象。
delete p;
return 0;
}