0

I'm learning about data structures by making a simple card game. In this code, i have a class Player, and a Queue containing all the players in the game.

the implementation of the Queue:

template < typename T >
    class Queue{
    int count;
    int front, rear;
    T entry[maxsize];
    public:
    Queue();
    bool empty();
    errorcode Append(T item);
    errorcode serve();
    errorcode retreive(T &item);
    };

The Queue constructor:

template <typename T>
    Queue<T>::Queue(){
        count = 0;
        rear = maxsize-1;
        front=0;
    }

And here is the Player class:

       class Player {
            int number;
            List<string> set;
        public:
            Player(int number, List<string> set) {
                this->number = number;
                this->set = set;
            }
            void draw();
            string play();
            .
            .
            .
        };

in the main function, i declare the Queue using this code:

Queue<Player> pl;

But i get the error 'no matching function for call to Player::Player()', this error is in the line where the queue constructor is implemented.

Soul DEV
  • 1
  • 1

1 Answers1

2

It's what it says (and has little to do with templates).

Queue<Player> has a member Player entry[maxsize], which requires the default-construction of maxsize Player objects.

But since Player has no default constructor, this is impossible.

How about a nice vector instead? You don't really need/want to allocate the maximum number of Players up-front anyway, surely.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055