的是自我学习的过程设计队列这里是代码执行队列
#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