I have a class Player and a class Team.
I want to create a vector of Players in constructor of class Team. I have written a method called fillVector witch creates all the players. I have added method fillVector into class Team witch is shown bellow. I do not think class Player is necessary.
When I compile my programm with codeblocks there is the following error:
Team.cpp|9|undefined reference to `Team::fillTeamVector(std::vector >&)'| |error: ld returned 1 exit status|
This is the Team.cpp code :
#include "Team.h"
#include <vector>
#include <iostream>
#include "Player.h"
Team::Team()
{
vector<Player> team;
fillTeamVector(team);
}
void fillTeamVector(vector<Player>& team){
cout << "How many players are in the team? " <<endl;
string name;
int teamSize,x,y,num,target_line;
cin >> teamSize;
for (int i=0 ; i<=teamSize ; i++){
cout << "Give player's name" << endl;
cin >> name;
cout << "Give player's number" << endl;
cin >> num;
cout << "Give player's x position" << endl;
cin >> x;
cout << "Give player's y position" << endl;
cin >> y;
cout << "Give player's target line" << endl;
cin >> target_line;
Player newPlayer(name,num,x,y,target_line);
team.push_back(newPlayer);
}
}
This is the Team.h code :
#ifndef TEAM_H
#define TEAM_H
#include <iostream>
#include <vector>
#include "Player.h"
using namespace std;
class Team
{
public:
Team();
void fillTeamVector(vector<Player>&);
};
#endif // TEAM_H
This is the main.cpp code :
#include <iostream>
#include <stdio.h>
#include "Player.h"
#include "Team.h"
using namespace std;
int main()
{
Team team;
return 0;
}