1
template <typename T> class Queue
{
template<typename T> ostream& operator<< (ostream& print, const Queue <T>& x)
{
print<<"\nThe elements are as : \n";
if(q.f!=-1)
{
int fr=q.f,rr=q.r;
while(fr<=rr)
print<<q.q[fr++]<<" <- ";
}
print<<endl;
}
//other stuffs
};
In main():
Queue<int> q(n); //object creation
cout<<q; //calling the overloaded << function
它是給我以下錯誤:重載<<與模板:爲什麼我會收到以下錯誤?
C:\Users\user\Desktop\PROGRAMS\queue_using_classes.cpp|16|error: declaration of 'class T'|
C:\Users\user\Desktop\PROGRAMS\queue_using_classes.cpp|3|error: shadows template parm 'class T'|
C:\Users\user\Desktop\PROGRAMS\queue_using_classes.cpp|16|error: 'std::ostream& Queue<T>::operator<<(std::ostream&, const Queue<T>&)' must take exactly one argument
'陰影模板parm'類T''什麼還不清楚呢? – tkausl
我不知道那是什麼錯誤。我只是試圖超載<<運營商與模板..... –
你知道什麼「陰影」是什麼意思? –