How to overload a function?

Below I have marked where I am getting an issue on calling my getter function. I was told that I need to Overload this function, how would I go about doing this? Any help offered is much appreciated.

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
  #include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;

class Person
{
private:

	vector<string> this_name;
	vector<int> this_number;
	vector<string> this_address;

public:

	// getters

	vector<string> get_Name() const      //const  states that the method will not change any value within the class.
	{
		return this_name;
	}
	vector<string> get_Address()  const
	{
		return this_address;
	}
	vector<int> get_PhoneNumber() const 
	{
		return this_number;
	}

	// setters

	void set_Name(vector<string> N)
	{ 
		this_name = N; 

	}
	void set_Address(vector<string> A)
	{
		this_address = A;
	}
	void set_PhoneNumber(vector<int> P)
	{
		this_number = P;
	}
};



int main()
{
	
	Person Name;
	Person Address;
	Person PhoneNumer;
	string x;
	vector<string> all_addresses;
	int Answer;
	int z;

	ifstream datain;
	ofstream dataout;

	dataout.open("Address Book.dat");

	cout << "Please type 1 to enter addresses or 0 to exit: ";
	cin >> Answer;

	while (Answer == 1)
	{
		int v = 0;
		cout << "How many addresses would you like to enter?: ";
		cin >> z;
		cin.ignore();

		while (v < z)
		{
	
			cout << "Enter 1 address: ";
			getline(cin, x);


			all_addresses.push_back(x); // takes each string and pushes it to the end of the vector. This is how we make our vector of strings
		    Address.set_Address(all_addresses); // sets your vector of addresses to the set_Address setter.
			cout << Address.get_Address(); // *********ERRROR IS HERE*************
			v++;
		}

		cout << "Please type 1 to enter an address or 0 to exit: ";
		cin >> Answer;
	}
		for (string a_address : all_addresses)
		{
			dataout << a_address << endl;
			cout << a_address << endl;
		}

	

	if (Answer == 0)
	{
		cout << "Program Terminating...";
		system("Pause");
		return 0;
	}
	
	system("Pause");
	return 0;
}
What is the error message?

Note that we can probably replicate the error with much simple code:
1
2
vector<string> foo;
cout << foo; // error 


How should a vector be printed out? There are many possibilities and therefore the standard library does not provide any default.
Hmmm, I see where you're getting at I do believe. To print out a vector would you need to iterate through each element and print it out like you would an array??
Exactly.

Besides, you should know for you already do print a vector on lines 93-97.
Thank you so much! Will mark it as solved :)
Topic archived. No new replies allowed.