返回信息流我想编一个通讯录,就是说构建一个结构变量,存入个人信息,然后用类的构造函数,我看不出来错哪儿了。。帮我看看啊,,谢谢啦
头文件
struct DataType
{
int ID;
char name[10];
char ch;
char phone[13];
char addr[31];
};
const int maxsize=100;
template <class T>
class communication
{
public:
communication(T a[],int n);
/*void add-information(T x);
void omit-information(int i);
void change-information(int i,T x);
void sort-information(int i);*/
private:
T data[maxsize];
int length;
}
communication<T>::communication(T a[],int n)
{
for(int i=0;i<n;i++)
{
data[i]=a[i];
length=n;
cout<<data[i].ID;
}
}
主函数
#include<iostream>
#include"header.h"
using namespace std;
int main()
{
DataType DataType1={1,"Rachel",'f',"132290876","New York"};
DataType DataType2={2,"Ross",'m',"145678906","Beijing"};
DataType DataType3={3,"Emily",'f',"190786503","London"};
DataType a[maxsize];
a[0]=DataType1;a[1]=DataType2;a[2]=DataType3;
communication sample(a[maxsize],maxsize);
}
这是一条镜像帖。来源:北邮人论坛 / cpp / #45590同步于 2010/11/3
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
这个程序哪儿错了
fei995440109
2010/11/3镜像同步3 回复
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
【 在 fei995440109 的大作中提到: 】
: 我想编一个通讯录,就是说构建一个结构变量,存入个人信息,然后用类的构造函数,我看不出来错哪儿了。。帮我看看啊,,谢谢啦
: 头文件
: struct DataType
: ...................
楼上说的对,当你用类模版的时候类模版形参是必须的。
template <class T> class Queue<int>{......};
Queue qs;//没有类模版形参
Queue<string> qs;//这样就对了。
另外你程序里还有些小错误,像类最后的花括号后面应该有“;”。
data 有成员变量ID吗????
类后没分号?????
【 在 fei995440109 的大作中提到: 】
: 我想编一个通讯录,就是说构建一个结构变量,存入个人信息,然后用类的构造函数,我看不出来错哪儿了。。帮我看看啊,,谢谢啦
: 头文件
: struct DataType
: ...................