Vector and Pointer Error C2039

I'm trying to write a program for a class where players participate in a rock paper scissors tournament. I'm currently working on option 2 which is supposed to add a player to the vector of players, but it's showing me an error on line 54. It appears under the .pushback part: error C2039: 'pushback' : is not a member of 'std::vector<_Ty>'.

I'm not sure why this is happening. .pushback should be a member of all vectors, right?

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
 #include <iostream>
#include "people.h"
#include <vector>
#include <string>

using namespace std;


void printplayers(vector<People> players)
{
	for (int i=0; i<players.size(); i++)
			{
				
				string name=players[i].getName();
				int wins=players[i].getwins();
				int losses=players[i].getlosses();
				int draws=players[i].getdraws();
				double winpercent= players[i].getwinpercent();

				cout<<name<<"   Wins:"<<wins<<"    Losses:"<<losses<<"   Draws:"<<"   Percent of wins:"<<endl<<endl;
			}

}
int main()
{
	int bob=0;
	while (bob==0)
	{
		cout<<"Welcome to the Arena! Please select an option!"<<endl;

		cout<<"(1) Show players"<<endl;
		cout<<"(2) Add a new player"<<endl;
		cout<<"(3) Add an existing player to the line-up"<<endl;
		cout<<"(4) Show the line-up"<<endl;
		cout<<"(5) FIGHT!"<<endl;
		cout<<"(0) Quit"<<endl;
		vector<People> players;
			
		int menuchoice;
		cin>>menuchoice;

		if (menuchoice==1)
		{
			cout<<"Your players:"<<endl;
			printplayers(players);
		}

		if (menuchoice==2)
		{
			cout<<"Please enter player name."<<endl;
			string playername;
			cin>>playername;
			People*enterthearea=new People(playername, 0, 0, 0, 0);
			players.pushback(enterthearena);

		}

		if (menuchoice==3)
		{
		}

		if (menuchoice==4)
		{
		}

		if (menuchoice==5)
		{
		}

		if (menuchoice==0)
		{
			return 0;
		}
	}
}
players.pushback(enterthearena);
should be:
players.push_back(*enterthearea);

Though I'm not sure you need a pointer here at all.
1
2
    People enterthearea(playername, 0, 0, 0, 0);
    players.push_back(enterthearea);
Last edited on
Oh gosh. I feel like a moron. I've been staring at this screen for far too long. Thank you!!
It may sound trite, but one of the hardest things about programming is believing what the compiler tells you. If it says that a function doesn't exist then you need to check your spelling very carefully. If that looks okay then check the class definition to see if you've got the name right. Don't rely on memory.

I can't tell you how many times I've seen people waste hours because they think "I know this part is okay so I won't look there" when in fact, that part is where the problem lies.
What does your people.h file look like? That could also be important to the error
Topic archived. No new replies allowed.