-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatamemberptr.cpp
More file actions
59 lines (50 loc) · 1.23 KB
/
datamemberptr.cpp
File metadata and controls
59 lines (50 loc) · 1.23 KB
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
/*
* =====================================================================================
*
* Filename: datamemberptr.cpp
*
* Description: Pointers as data members
*
* Version: 1.0
* Created: 03/01/13 20:53:53
* Revision: none
* Compiler: gcc
*
* Author: Robert Halliday (rh), rob_halliday_1@hotmail.com
* Company: rphhpr
*
* =====================================================================================
*/
#include <iostream>
class SimpleCat
{
public:
SimpleCat();
~SimpleCat();
int GetAge() const { return *itsAge; }
void SetAge(int age) { *itsAge = age; }
int GetWeight() const { return *itsWeight; }
void SetWeight(int weight) { *itsWeight = weight; }
private:
int * itsAge;
int * itsWeight;
};
SimpleCat::SimpleCat()
{
itsAge = new int(2);
itsWeight = new int(5);
}
SimpleCat::~SimpleCat()
{
delete itsAge;
delete itsWeight;
}
int main()
{
SimpleCat * Frisky = new SimpleCat;
std::cout << "Frisky is " << Frisky->GetAge() << " years old\n";
Frisky->SetAge(5);
std::cout << "Frisky is " << Frisky->GetAge() << " years old\n";
delete Frisky;
return 0;
}