I have the following code:
#include<bits/stdc++.h>
using namespace std;
class Player{
public:
string name;
int s, t;
Player(string name, int s, int t){this->name=name, this->s=s, this->t=t;}
virtual int getHability() = 0;
};
class PlayerType1: Player{
public:
PlayerType1(string name, int s, int t):Player(name, s, t){};
int getHability(){return this->s+2*this->t;}
};
class PlayerType2: Player{
public:
PlayerType2(string name, int s, int t):Player(name, s, t){};
int getHability(){return 2*this->s+this->t;}
};
class Team{
vector<unique_ptr<Player>> players;
Team(const Team& team){
/*problem here!!*/
}
};
int main(){
return 0;
}
Basically I have an abstract class that represents a player and derived class of specific types of players (striker, defender).
I also have a class of team and I'm storing the players of that team using std::unique_ptr
pointing to my Player class.
My problem arises when I try to create a copy constructor in the Team class and have to pass the vector of unique pointers from one class to another. Since I'm using a unique pointer I would have to dereference it to copy the vector (based on this). But when I try to deference it, the compiler gives me an error since it is an abstract class. Is there any possible way to do it?
I'm open to suggestions on another way to store the players if my method is not correct.