forked from JiauZhang/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructor.cpp
More file actions
45 lines (39 loc) · 879 Bytes
/
constructor.cpp
File metadata and controls
45 lines (39 loc) · 879 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;
//#define DEBUG
#ifdef DEBUG
#define debug(numbers, length) print_numbers(numbers, length)
#else
#define debug(numbers, length)
#endif
class constructor
{
public:
int value;
constructor(): value(10) {}
};
//又把 main 写错 ~ ~ ~ ~ ~ ~ ~
//错误提示:18 undefined reference to `WinMain@16'
int main(int argc, char** argv)
{
constructor* ctr = new constructor[5];
char* ch = new char[5];
cout << ctr->value << ' ';
//第一种访问方法
for(int i=0; i<5; i++) {
//ctr是作为数组名来用的,ctr[i]就是实例对象了,不再是指针了
/*
constructor ct = ctr[i];
cout << ct.value << ' ';
*/
cout << ctr[i].value << ' ';
}
cout << endl;
//第二种访问方法
constructor* end = ctr+5-1;
cout << end->value << ' ';
for(;end>=ctr;end--) {
cout << end->value << ' ';
}
return 0;
}