vc++的高手们,麻烦看看这个错误,应该怎么改正啊!!

源程序:#include<iostream.h>#include<malloc.h>#include<string.h>#defineNULL0#defineLENsiz... 源程序:
#include <iostream.h>
#include<malloc.h>
#include <string.h>
#define NULL 0
#define LEN sizeof(struct headtitle)
class headname
{
private:
struct headtitle
{
char name[20];
struct headtitle *next;
};

public:
int n;
struct headtitle *input()
{
struct headtitle *head;
struct headtitle *p1,* p2;
n=0;
p1=p2=(struct headtitle*) malloc (sizeof(struct headtitle));
cout<<"Please Input What Titles You Need!(输入0代表结束)"<<"\n";
cin>>p1->name;
head=NULL;
while (strcmp(p1->name, "0") != 0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct headtitle *)malloc (sizeof(struct headtitle));
cin>>p1->name;
}
p2->next=NULL;
return(head);
}
void showtitle(struct headtitle *head)
{
struct headtitle *p;
p=head;
if(head!=NULL)
do
{
cout<<p->name<<"\t";
p=p->next;
}while(p!=NULL);
}
void freetitle(struct headtitle *head)
{
delete head;
cout<<"It's Succeed to Delete!";
}
};

int main()
{
struct headtitle *hd;
cout<<"Start Testing"<<"\n";
headname head1;
hd=head1.input();
head1.showtitle(hd);
head1.freetitle(head1.input());
cout<<"\n"<<"Text Over!"<<"\n";
return 0;
}

错误1:F:\Visual C++ 6.0 File\heads2\head.cpp(62) : error C2664: 'showtitle' : cannot convert parameter 1 from 'struct main::headtitle *' to 'struct headname::headtitle *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

错误2:F:\Visual C++ 6.0 File\heads2\head.cpp(62) : error C2664: 'showtitle' : cannot convert parameter 1 from 'struct main::headtitle *' to 'struct headname::headtitle *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

急啊!!!麻烦各位大虾啦!!!
如果我想把headtitle结构体放在headname类里面,那么我该怎么做才能避免这样的错误?
展开
 我来答
百度网友ae3e84a
2008-12-09 · 超过46用户采纳过TA的回答
知道小有建树答主
回答量:340
采纳率:0%
帮助的人:187万
展开全部
改成这样子 结构体的声明放在类的外部
如果在类中用结构体的变量直接用就行了
结构体也是一种数据类型 不要放在类里
#include <iostream.h>
#include<malloc.h>
#include <string.h>
#define NULL 0
#define LEN sizeof(struct headtitle)
struct headtitle
{
char name[20];
struct headtitle *next;
};
class headname
{
private:
headtitle *head;//当用的时候直接用就行了
headtitle *p1,* p2;//同上

public:
int n;
struct headtitle *input()
{
headtitle *head;
headtitle *p1,* p2;
n=0;
p1=p2=(struct headtitle*) malloc (sizeof(struct headtitle));
cout<<"Please Input What Titles You Need!(输入0代表结束)"<<"\n";
cin>>p1->name;
head=NULL;
while (strcmp(p1->name, "0") != 0)
{
n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct headtitle *)malloc (sizeof(struct headtitle));
cin>>p1->name;
}
p2->next=NULL;
return(head);
}
void showtitle(struct headtitle *head)
{
struct headtitle *p;
p=head;
if(head!=NULL)
do
{
cout<<p->name<<"\t";
p=p->next;
}while(p!=NULL);
}
void freetitle(struct headtitle *head)
{
delete head;
cout<<"It's Succeed to Delete!";
}
};

int main()
{
struct headtitle *hd;
cout<<"Start Testing"<<"\n";
headname head1;
hd=head1.input();
head1.showtitle(hd);
head1.freetitle(head1.input());
cout<<"\n"<<"Text Over!"<<"\n";
return 0;
}
幸巴达
2008-12-09 · TA获得超过1.2万个赞
知道大有可为答主
回答量:6953
采纳率:38%
帮助的人:2461万
展开全部
headtitle结构体属于headname类里面的, main函数里面不能这样声明:
struct headtitle *hd;

把headtitle放到class headname之前.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式