一个小程序执行时的问题
请教各位大侠,有这样一段程序:
#ifndef TEMPLATE_STORE_CLASS
#define TEMPLATE_STORE_CLASS
#include<iostream.h>
#include<stdlib.h>
template<class T>
class Store
{
private:
T item;
int haveValue;
public:
Store(void);
T GetElement(void);
void PutElement(T x);
};
template<class T>
Store<T>::Store(void):haveValue(0)
{}
template<class T>
T Store<T>::GetElement(void)
{
if (haveValue==0)
{
cout<<"No item present!"<<endl;
exit(1);
}
return item;
}
template<class T>
void Store<T>::PutElement(T x)
{
haveValue++;
item=x;
}
#endif
#ifndef STUDENT
#define STUDENT
struct Student
{int studID;
float gpa;
};
#endif
#include<iostream.h>
void main (void)
{
Student graduate={1000,23};
Store<int> A,B;
Store<Student> S;
Store<double> D;
A.PutElement(3);
B.PutElement(-7);
cout<<A.GetElement()<<" "<<B.GetElement()<<endl;
S.PutElement(graduate);
cout<<"The stucdent id is "<<S.GetElement().studID<<endl;
cout<<"Rentrieving object D ";
cout<<D.GetElement()<<endl;
}
为何编译通过了,但是却运行不起来,还请各位指教,谢谢!