struct array as function parameter problem

Hi everyone.
I have an array of a struct that I'm trying to pass to a function. When I just use the name of the array (list) in the function call, the compiler underlines the function name and says "Error: more than one instance of the overloaded function matches the argument list" and when I try it as list[], it underlines the ] and says "Error: expected an expression." Unfortunately, I'm a newbie and don't know what these mean. Please help!

Here's some of my code:

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
#include<iostream>
#include<cstring>
#include<fstream>

using namespace std;

const int MAX_CHAR = 101;
const int CAPACITY = 50;

struct Item
{
	char courseName[MAX_CHAR];
	char task[MAX_CHAR];
	char dueDate[MAX_CHAR];
};

void getItem(Item list[], char prompt[], int maxChar);

int main ()
{
	Item list[CAPACITY];

	getItem(list[], "Please enter the course name: ", MAX_CHAR);

	return 0;
}

void getItem(Item list[], char prompt[], int maxChar)
{
	int i = 0;

	cout << prompt;
	cin.get(list[i].courseName, maxChar, '\n');
	i++;
	cin.ignore();
}


Thanks for your help!
This line:
getItem(list[], "Please enter the course name: ", MAX_CHAR);

Should be:
getItem(list, "Please enter the course name: ", MAX_CHAR);

You're passing the entire array so you just need the name. In your function prototype and definition, the compiler needs to know it's an array so you can modify it.

Also, your loop doesn't work in getItem, unless you intended it to only get one item. But everytime you call getItem how it is now, it will always ONLY set the first index of the array.
That's what I thought, but when I do it like this:
getItem(list, "Please enter the course name: ", MAX_CHAR);
it underlines getItem and says "Error: more than one instance of the overloaded function matches the argument list."

I haven't written any other functions yet and only call getItem once so far. So, what's up with that?

Thanks again for you help. :)
Tested and works:
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
#include<iostream>
#include<cstring>
#include<fstream>

using namespace std;

const int MAX_CHAR = 101;
const int CAPACITY = 50;

struct Item
{
	char courseName[MAX_CHAR];
	char task[MAX_CHAR];
	char dueDate[MAX_CHAR];
};

void getItem(Item list[], char prompt[], int maxChar);

int main ()
{
	Item list[CAPACITY];

	getItem(list, "Please enter the course name: ", MAX_CHAR);

	return 0;
}

void getItem(Item list[], char prompt[], int maxChar)
{
	int i = 0;

	cout << prompt;
	cin.get(list[i].courseName, maxChar, '\n');
	cin.ignore();
	cout << list[i].courseName;
	i++;
}
Please enter the course name: apple
apple


Are you sure that you weren't changing the function prototype and definition parameters as well?
Oops... I had my function prototypes before my struct definition in my full program. I changed it and that fixed it.

Thanks for your help. :)
Topic archived. No new replies allowed.