SOS:一个文件链接的问题(特邀版主和各位高手指点)
以下是我的代码,分三个文件,写在一个文件里头没有问题,但是分开就是无法正确链接。请指教。//头文件 muban.h
#include <iostream>
#include<cstdlib>
using namespace std;
struct student
{
int id;
float gpa;
};
template <typename T>
class store
{
T item;
int havevalue;
public:
store();
T getelem(void);
void putelem(T x);
};
//实现文件 muban.cpp
#include "muban.h"
template<class T>
T store<T>::getelem(void)
{
if(havevalue==0)
{
cout<<"No item present!"<<endl;
exit(1);
}
return item;
}
template<class T>
void store<T>::putelem(T x)
{
havevalue++;
item=x;
}
template<class T>
store<T>::store():havevalue(0)
{}
//主函数 main.cpp
#include "muban.h"
int main()
{
student g={1000,23};
store<int> s1,s2;
store<student> s3;
store<double> D;
s1.putelem(3);
s2.putelem(-7);
cout<<s1.getelem()<<ends<<s2.getelem()<<endl;
s3.putelem(g);
cout<<"the student id is "<<s3.getelem().id<<endl;
cout<<"retrieving object D ";
cout<<D.getelem()<<endl;
system("pause");
}