的是自我學習的過程設計隊列這裏是代碼執行隊列
#include <iostream>
using namespace std;
template <class T>
class Queue{
public:
T * q;
int n, head, tail;
public:
Queue(int maxn){
q=new T[maxn+1];
n=maxn+1; head=n;
tail=0;
}
int emty() const {
return ((head%n)==tail);
}
void put(T k){
a[tail++]=k; tail=tail%n;
}
T get(){
head=head%n; return q[head++];
}
};
template <class T>
int main(){
Queue<int>a(10);
a.put(13);
a.put(45);
a.put(12);
a.put(10);
a.put(30);
a.put(45);
while(!a.emty()){
cout<<a.get()<<" ";
}
return 0;
}
這裏是錯誤
1>------ Build started: Project: QUEUE, Configuration: Debug Win32 ------
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>D:\c++_algorithms\QUEUE\Debug\QUEUE.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
請幫助
定義`main`爲模板,真正顯示出巨大的不理解。希望OP使用一本好的C++書。 – 2010-12-02 15:54:20
@Steve - 你可能想回讀他的其他問題:http://stackoverflow.com/questions/3406407/can-functions-be-in-a-struct。我們是他的C++書。 – 2010-12-07 19:08:03