blob: a361df0849ad9afefc461179d931a13a7eec041c (
plain)
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
73
74
75
76
77
78
79
80
|
//===-- main.cpp ------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include <string.h>
#include <vector>
#include <iostream>
class CustomString
{
public:
CustomString (const char* buffer) :
m_buffer(nullptr)
{
if (buffer)
{
auto l = strlen(buffer);
m_buffer = new char[1 + l];
strcpy(m_buffer, buffer);
}
}
~CustomString ()
{
delete[] m_buffer;
}
const char*
GetBuffer ()
{
return m_buffer;
}
private:
char *m_buffer;
};
class NameAndAddress
{
public:
CustomString& GetName() { return *m_name; }
CustomString& GetAddress() { return *m_address; }
NameAndAddress(const char* N, const char* A) : m_name(new CustomString(N)), m_address(new CustomString(A))
{
}
~NameAndAddress()
{
}
private:
CustomString* m_name;
CustomString* m_address;
};
typedef std::vector<NameAndAddress> People;
int main (int argc, const char * argv[])
{
People p;
p.push_back(NameAndAddress("Enrico","123 Main Street"));
p.push_back(NameAndAddress("Foo","10710 Johnson Avenue")); // Set break point at this line.
p.push_back(NameAndAddress("Arpia","6956 Florey Street"));
p.push_back(NameAndAddress("Apple","1 Infinite Loop")); // Set break point at this line.
p.push_back(NameAndAddress("Richard","9500 Gilman Drive"));
p.push_back(NameAndAddress("Bar","3213 Windsor Rd"));
for (int j = 0; j<p.size(); j++)
{
NameAndAddress guy = p[j];
std::cout << "Person " << j << " is named " << guy.GetName().GetBuffer() << " and lives at " << guy.GetAddress().GetBuffer() << std::endl; // Set break point at this line.
}
return 0;
}
|