C++新手求高手来帮忙看看这段代码

来源:百度知道 编辑:UC知道 时间:2024/06/04 00:57:14
我本本用的Vista只能装Visual 2008,今天编了段类模板的代码,想把类的定义和成员函数实现分成连个文件结果就报错。以下的代码还请高手帮忙看看
一、store.h文件
#include "iostream"
using namespace std;
//------------------------------------------------------------------------------------------------------------------
//定义结构体student
//------------------------------------------------------------------------------------------------------------------
struct student
{
int id;
float gpa;
};
//------------------------------------------------------------------------------------------------------------------
//定义store类模板
//------------------------------------------------------------------------------------------------------------------
template <class T>
class store
{
private:
T item;
int haveValue;
public:
store(void);
T getElem(void);
void putElem(T x);
};
二、store.cpp文件
#include "store.h"
//---

不太清楚你的要求,我把#include "store.h" 那段给删了,能运行(结果如下):
主函数被调用
store构造函数被调用
store构造函数被调用
store构造函数被调用
store构造函数被调用
3 -7
The student's id is...1000
Retrieving object DNo item present! //所以估计你落了头文件store.h~~

头文件都加全了吗?