我正在尝试制作使用模板的类的队列,但是当我尝试使用函数前或后面时,我会发现一个错误,说操作员"<<"不匹配功能。但是,如果我使用功能大小,则可以正常工作。所以,我想知道这可能是因为队列中的对象的顺序?我已经试图超载<<操作员但没有工作。谢谢你的帮助。这是我的代码:
//STL queue container
queue<stackType<int>> stack5;
stack5.push(5);
stack5.push(8);
stack5.push(6);
cout << "The front element of stack5 is: " << stack5.front() << endl;
假设您是指标准库的<queue>
,而不是90年代的传统STL,您的stack5.front()
是stackType<int>
类型。
如果您将这种类型与流插入器<<
一起使用,则需要定义ostream& operator<<(ostream&, const stackType<T> &)
。