c++ - 将类对象发送到模板类不起作用
问题描述
我正在尝试将对象发送到 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)'
解决方案
推荐阅读
- r - 如何将点击侦听器附加到 DT 和 Shiny 中的数据表?
- javascript - 检查放大数据存储操作的状态
- java - 错误:android.widget.RelativeLayout 无法转换为 androidx.recyclerview.widget.RecyclerView
- android - Android 10蓝牙断开后台服务
- laravel - Flutter App 中无法监听来自 Laravel 服务器的 Socket IO
- docker - 在容器优化操作系统中以 JSON 形式注入日志
- c++ - 如何检查模板中发送的参数类型?
- python - 如何在 dm-script 中将 ImageDocument 设置为不脏
- laravel - Laravel 7 Api 不完整?
- android - 设置填充不会更新视图