Error message, newbie

Line 26** initialize function does not take 4 arguments, working on a code that will allow me to see add, and search for a team. Just trying to take it bit by bit right now

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
#define NUM_TEAMS 4
#define NUM_MEMBERS 3
int teamCounter = 4;

void initialize();

struct TeamS
{
	int ID;
	string teamMembers[3];
};

vector <TeamS>TeamV;

int main()
{
	const int ID[NUM_TEAMS] = { 123, 321, 456, 789 };
	const string MEMBERS[NUM_TEAMS][NUM_MEMBERS] =
	{
		{ "Sarah", "Joe", "John" },
		{ "Chris", "Kevin", "James" },
		{ "Tom", "Kim", "Emily" },
		{ "Jill", "Jason", "Jim" }
	};

**initialize(TeamV, ID, MEMBERS, 3);
TeamS* t = new TeamS;
for (int i = 0; i < sizeof(ID); i++)
{
	cout << ID[i];
	t->ID = ID[i];
	for (int j = 0; j < 4; j++)
	{
		for (int k = 0; k < 4; k++)
		{
			t->teamMembers[i] = MEMBERS[j][k];
			cout << t->teamMembers[i];
		}
	}
	TeamV.push_back(*t);
};

system("pause");
return 0;
}

void initialize(vector <TeamS> & TeamV, const int id[],
	const string m[][NUM_MEMBERS], int arraySize)
{
	TeamS teams;
	for (int i = 0; i < sizeof(id); i++)
	{
		teams.ID = id[i];
		for (int j = 0; j < arraySize; j++)
		{
			for (int k = 0; k < arraySize; k++)
			{
				teams.teamMembers[i] = m[j][k];
			}
		}
		TeamV.push_back(teams);
	}
}

void initialize()
{
}
Last edited on
Line 5: Your function prototype for initialize() states it takes no arguments.

Line 26: You attempt to call initialize() with 4 arguments. The compiler has not seen a prototype (or definition) that takes 4 arguments, hence the error. Remove line 5.
Add after line 13:
 
void initialize(vector <TeamS> & TeamV, const int id[],const string m[][NUM_MEMBERS], int arraySize);

Remove lines 65-67.
Ah, I see. Thanks, I had tried that earlier, except I left it at line 5 which was causing an error, but now it seems to be fine now.

Now at the moment it compiles perfectly fine, however I'm receiving a runtime error..
"Exception thrown at 0x0F9C4AE9 (vcruntime140d.dll) in CMSY2L2.exe: 0xC0000005: Access violation writing location 0xF179D0EC."

It doesn't say exactly where it is occurring, I'm assuming some sort of overload with the vector?
One more error:
Line 51: sizeof(id) That's not going to give you the size of the id array. It's going to give you the size of a pointer.

As for your runtime error, use your debugger to find where the error is occurring.
Topic archived. No new replies allowed.