-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeapStackPony
68 lines (47 loc) · 1.16 KB
/
HeapStackPony
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
#pragma once
#include <iostream>
class Pony {
private:
std::string name;
int legs;
public:
//Pony() = default;
Pony(std::string PonyName, // constructor
int PonyLegs);
Pony(const Pony& CopyPony) // copy constructor
{
name = CopyPony.name;
legs = CopyPony.legs;
};
~Pony(); // destructor
int GetPonyLegs() const { return legs; }
std::string GetPonyName() const { return name; }
};
#include "Pony.h"
#include <iostream>
Pony::Pony(std::string Ponyname, int Ponylegs)
: name(Ponyname), legs(Ponylegs)
{
printf("Constructed\n");
}
Pony::~Pony()
{
printf("destructed\n");
}
#include "Pony.h"
#include <iostream>
std::string PonyOnTheHeap(std::string& name) { return name; }
int PonyOnTheStack(int& legs) { return legs; }
//void functInputclass(const Pony& input) {}
int main()
{
Pony PonyOnStack("Stack", 4);
Pony* PonyOnHeap = new Pony("Heap", 3);
//allocated on the heap
std::string name = PonyOnHeap->GetPonyName();
std::cout << "Heap Pony name: " << PonyOnTheHeap(name) << std::endl;
delete PonyOnHeap;
//allocated on the stack
int legs = PonyOnStack.GetPonyLegs();
std::cout << "Stack Pony legs: " << PonyOnTheStack(legs) << std::endl;
}