一个关于c++中的问题(尤其为 指针)

#include"iostream.h"#include"string.h"template<classT,classM>classstudent{private:Tna... # include "iostream.h"
# include "string.h"

template<class T,class M>
class student
{
private:
T name[10];
M age;
static M length;
public:
student();
void input();
void dele();
void out_top();
void output();
};

template<class T,class M>
student<T,M>::student()
{
name = NULL;
age = 0;
}

template <class T,class M>
M student<T,M>::length = 0;

template<class T,class M>
void student<T,M>::input()
{
M i;

cout<<"Please input the length:"<<endl;
cin>>length;

cout<<"Please input the information:"<<endl;
for (i = 0; i < length; i++)
{
cin>>student[i].name>>student[i].age;
}

}

template<class T,class M>
void student<T,M>::dele()
{
M i;

for (i = 1; i < length; i ++)
{
strcpy(student[i-1].name,student[i].name);
student[i-1].age = student[i].age;
}

length --;
}

template<class T,class M>
void student<T,M>::out_top()
{
cout<<"The top student's information:"<<endl;
cout<<"name:"<<student[0].name<<" "<<"age:"<<student[0].age<<endl;
}

template<class T,class M>
void student<T,M>::output()
{
M i;

for (i = 0; i < length; i ++)
{
cout<<"name:"<<student[i].name<<" "<<"age:"<<student[i].age<<endl;
}
}

void main()
{
student<char,int> *head;

head = new student<char,int>[10];
head->input();
head->out_top();
head->dele();
head->output();
}

请高手帮忙改一下!!!谢谢!!!
不好意思,忘记了:想用类模板来实现:创建一个学生类,先输入 姓名和年龄,后删除栈顶元素 ,输出栈顶元素 ,将所有信息全部输出 ,但在指针上出了问题!!!
展开
 我来答
百度网友21ccbbcc2
2010-12-12 · TA获得超过374个赞
知道小有建树答主
回答量:273
采纳率:0%
帮助的人:352万
展开全部
#include <iostream>
#include <string>
using namespace std;
template<class T,class M>
class student
{
private:
T name[10];
M age;
static M length;
public:
student();
void input();
void dele();
void out_top();
void output();
};

template<class T,class M>
student<T,M>::student()
{
memset(&name,0,sizeof name);
age = 0;
}

template <class T,class M>
M student<T,M>::length = 0;

template<class T,class M>
void student<T,M>::input()
{
M i;

cout<<"Please input the length:"<<endl;
cin>>length;

cout<<"Please input the information:"<<endl;
for (i = 0; i < length; i++)
{
cin >> this[i].name >> this[i].age;
}

}

template<class T,class M>
void student<T,M>::dele()
{
M i;

for (i = 1; i < length; i ++)
{
strcpy(this[i-1].name,this[i].name);
this[i-1].age = this[i].age;
}

length --;
}

template<class T,class M>
void student<T,M>::out_top()
{
cout<<"The top student's information:"<<endl;
cout<<"name:"<<this[0].name<<" "<<"age:"<<this[0].age<<endl;
}

template<class T,class M>
void student<T,M>::output()
{
M i;

for (i = 0; i < length; i ++)
{
cout<<"name:"<<this[i].name<<" "<<"age:"<<this[i].age<<endl;
}
}

int main()
{
student<char,int> *head;

head = new student<char,int>[10];
head->input();
head->out_top();
head->dele();
head->output();
}

我改了下,在我这里是能正常运行的。你试试吧。
你关键是看错了吧,把函数名看成是参数了。估计是从C转来C++的? :-)
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
回头的世界
2010-12-12 · TA获得超过471个赞
知道小有建树答主
回答量:580
采纳率:0%
帮助的人:416万
展开全部
你的题目问题在哪里?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式