求大神指导,加粗的行有错误无error C2440:

error C2440: 无法从“student”转换为“student * 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符


#include<iostream>

#include<fstream>

#include<string.h>

#include<conio.h>              //用getch();

using namespace std;


//学生类

class student

{

public:

    char Id[20];

    char name[10];

    char sex[3];

long telephone;

student*Next;

//student(long xh,char nm[],char sx[],long tel)

//{

// xuehao=xh;

// strcpy(name, nm);

// strcpy(sex, sx);

// telephone = tel;

//}

void newstudent();

void input()

{

cout << "学号:"; cin >> Id;

cout << "姓名:"; cin >> name;

cout << "性别:"; cin >> sex;

cout << "电话:"; cin >> telephone;

}

void ReadFile(istream&in)

{

cin >> Id >> name >> sex >> telephone;

}

void show() const

{

cout << "学号" << Id;

cout << "姓名" << name;

cout << "性别" << sex;

cout << "电话" << telephone;

}

}newstudent;


//教师类

class teacher

{

public:

long teachernumber;

char name[10];

long classnumber;

char classname[10];

char commentperformance[100];


/*teacher(long tnum, char nm[], long cnum, char cnm[], char comper[])

{

teachernumber = tnum;

strcpy(name, nm);

classnumber = cnum;

strcpy(classname, cnm);

strcpy(commentperformance, comper);

}*/

void teacherinput()

{

cout << "教师编号:"; cin >> teachernumber;

cout << "教师名称:"; cin >> name;

cout << "任教课程编号:"; cin >> classnumber;

cout << "任教课程名:"; cin >> classname;

cout << "评教成绩:"; cin >> commentperformance;

}

void show() 

{

cout << "教师编号:"<< teachernumber;

cout << "教师名称:"<< name;

cout << "任教课程编号:"<<classnumber;

cout << "任教课程名:"<<classname;

cout << "评教成绩:"<<commentperformance;

}

};


//评教类

class commentsystem

{

public:

commentsystem();

~commentsystem();

void showmenu();

void showinformation();

void find();

void save();

void modifyinformation();

void removeinformation();

void swap(student*, student*);

void display()

{

for (student*p = Head->Next; p != End;p=p->Next)

p->show();

cout << "输入任意字符!继续……";

getch();

}

void addinformation()

{

End->input();

End->Next = newstudent();

End = End->Next;

cout << "添加成功!" << endl;

cout << "输入任意字符!继续……";

getch();

}

private:

student*Head, *End;

ifstream in;

ofstream out;

student*FindItem(char*name)

{

for (student*p = Head; p->Next != End; p = p->Next)//匹配成功则返回上一个指针,不成功就返回空

if (!strcmp(p->Next->name, name))return p;

return NULL;

}

student*FindID(char*Id)

{

for (student*p = Head; p->Next != End; p = p->Next)//匹配成功则返回上一个指针,不成功就返回空

if (!strcmp(p->Next->Id, Id))return p;

return NULL;

}

};


//构造函数

commentsystem::commentsystem()

{

Head = newstudent;

Head->Next = newstudent;

End = Head->Next;

in.open("D:/sort.txt");

if (!in)

cout << "这是一个新系统,无学生信息。请先输入。" << endl;

else

{

while (!in.eof())

{

End->ReadFile(in);

if (End->name[0] == '\0')break;

End->Next = newstudent;

End = End->Next;

}

in.close();

cout << "\t\t读取学生信息成功!" << endl;

}

}


//析构函数

commentsystem::~commentsystem()

{

save();

for (student*temp; Head->Next != End;)

{

temp = Head->Next;

Head->Next = Head->Next->Next;

delete temp;

}

delete Head, End;

}


//菜单

void commentsystem::showmenu()

{

cout << "^^^^^^^^^^学生评教系统^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^1.输入学生信息^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^2.输入教师信息^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^3.输入评教信息^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^4.查找信息^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^5.删除信息 ^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^6.修改信息^^^^^^^^^^" << endl;

cout << "^^^^^^^^^^0.退出^^^^^^^^^^" << endl;

cout << "请选择:";

}


//查找函数

void commentsystem::find()

{

char name[20], Id[10];

int x;


qq_sdfedfew_0
浏览 1072回答 1
1回答

宾丶高

newstudent 应写成 new student ,你写来连着了,不知道是不是粘贴到这边的错误,反正我这边改了之后编译没有问题
打开App,查看更多内容
随时随地看视频慕课网APP