Problems understanding OOP

ok i am trying to use oop to create a player class but i am having a problem passing the player class through a vector. Im not sure what i am doing wrong any help is apreciated.
this is the error i am getting
error C2064: term does not evaluate to a function taking 1 arguments
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
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int numberOfplayers();
int totalPlayers;

class player{
public:
	int Setdificulty();
	string Setname();
	int Setscore();
private:
	string name;
	int dificulty;
	int score;
};
vector<player> Pl;
void main()
{
	int i;
	cin >> totalPlayers;
	for(i = 0; i <totalPlayers; i++)
    Pl.push_back(Pl(i));//this is the line that is causing me problems 
}
Are you sure you should be using brackets and not square brackets?
Judging from your program, you're trying to read in one "player" object at a time into the vector, correct? In that case, you should assemble the player from user input in a temporary object, and then push that onto the vector. I can't really figure out how the line you have would work, without further clarification.
Last edited on
I think i figured it out i needed to change (Pl(i)) to (player(i)) to match my class I am trying to create a set amount of players then update there information as they enter it.
Last edited on
Those brackets for the i will still have no meaning. You have no constructor for the player class nor do you have an overload for the call operator, so what are the brackets supposed to be?
This can compile if you remove the i and leave it as Pl.push_back(Pl());.
Alternatively (and preferably), you could do away with the loop and just call Pl.resize(totalPlayers);
Or, better still, make Pl local to main() and create it the right size: std::vector<player> Pl(totalPlayers);

By the way, main() is supposed to always return int.
Topic archived. No new replies allowed.