首页 > 解决方案 > 将类对象发送到模板类不起作用

问题描述

我正在尝试将对象发送到 C++ 中的另一个模板类,但出现错误。这是代码。我怎么解决这个问题?我想创建一个带有乘客类型的队列。

主程序

#include<iostream>
#include "Queue.h"

class Passenger{
    private:
        string name,surname,destination;
    public:
        Passenger (string name, string surname, string destination)
        {
            this->name = name;
            this->surname = surname;
            this->destination = destination;
        }
int main()
{
    Queue<Passenger> passenger;
    passenger.insertQueue(Passenger("Batuhan","Gunes","Istanbul")); //HERE IS ERROR
    return 0;
}

队列.h

#ifndef Queue_h
#define Queue_h
#include<iostream>
#include<cassert>
using namespace std;


template <class T>
class Queue{
        int max;
        int count;
        int front, rear;
        T *list;
    public:
        Queue(int = 100)

        //Inserts a new item to the queue. Inserts are always dont at the rear
        void insertQueue(T& item);
};


template <class T>
void Queue<T>::insertQueue(T& item)
{
    if(!isFull())
    {
        rear = (rear+1) % max;
        list[rear] = item;
        count++;
    }
    else
    {
        cerr<<"No space left in the queue!"<<endl;
    }
}

错误消息
[错误] 没有匹配函数调用 'Queue::insertQueue(Passenger)'

标签: c++oop

解决方案


推荐阅读