SFAfreshman 2019-03-31 19:20 采纳率: 50%
浏览 2041
已采纳

rror C2084: 函数“Student::~Student(void)”已有主体 1> : 参见“{dtor}”的前一个定义

报错说已有主体。但我检查没有啊跪求大佬解惑(一个c++学生信息系统)

#include<string.h>
using namespace std;
#define SIZE 80         //宏定义语句!!不要加;
class Student
{
private:
    char*name;          //姓名
    char ID[19];        //身份证
    char number[10];    ///学号
    char speciality[20];//专业
    int age;            //年龄
public:
    Student();
    Student(char*n,char *id,char *nm,char *spe,int a);//有参构造//定义为静态数组,参数仍为字符指针,获取函也为指针
    Student(const Student&pre);
    ~Student();
    void intput();
    void output();
    char* getname();
    char* getID();
    char* getnumber();
    char* getspec();
    int getage();
};
#endif
#include"identify student.h"
//ps:".h"文件的实现的cpp文件需要和.h文件同名为约定俗成:(cpp文件中包含了.h就会被编译器识别)
Student::Student ()
{}                                      //无参构造函数
Student::Student(char*n,char *id,char *nm,char *spe,int a)  //有参构造函数    
{
    if(n)
    {
        name=new char[strlen(n)+1];
        strcpy(name,n);
    }
    id=ID;
    nm=number;
    spe=speciality ;
    a=age;
}
Student::~Student ()
{
    if(name)
        delete[]name;
}
Student::Student(const Student&pre)                     //拷贝构造函数
{
    if(pre.name)
        {
            delete[]name;
            name=new char[strlen(pre.name)+1];
            strcpy(name,pre.name);
        }
    else name=0;
    strcpy(ID,pre.ID);
    strcpy(number,pre.number);
    strcpy(speciality ,pre.speciality );
    age=pre.age;
}
void Student::output()
{
    cout<<"姓名"<<age<<endl;
    cout<<"年龄"<<age<<endl;
    cout<<"身份证号码"<<ID<<endl;
    cout<<"专业"<<speciality <<endl;
    cout<<"学号"<<number<<endl;
}
void Student ::intput()
{
    char n[10];
    cout<<"输入姓名:";                //通过判断使输入兼容了修改函数的功能?
    cin>>n ;
    if(name)delete []name;            
    name=new char[ strlen(n)+1];
    strcpy( name, n );
    cout<<"输入身份证:";
    cin>>ID ;
    cout<<"输入年龄:";
    cin>>age; 
    cout<<"输入专业:";
    cin>>speciality ;
    cout<<"输入学号:";
    cin>>number;       
}
Student::~Student()
{
    if(name)
        delete[]name;
}
int Student::getage()
{
    return age;             //获取年龄
}
char*Student::getID ()
{
    return ID;              //获取身份证
}
char*Student::getname ()
{
    return name;            //获取姓名
}
char*Student::getnumber()
{
    return  number;         //获取学号
}
char*Student::getspec()
{
    return speciality ;     //获取专业
}

#include<iostream>
#include "identify student.h"

using namespace std;
const int N=10;                             //最大学生人数

void menu();                                //显示菜单
void OutputStu( Student *array );           //输出学生信息
void IntputStu(Student *array);             //输入学生信息
int  SearchStu( Student *array, char *na);  //查询学生信息

int Count=0;                                //全局变量:当前学生人数

int main()
{
    Student array[N];                       //声明学生对象数组
    int choice;

    do
    {
        menu();
        cout<<"Please Intput your choice:";
        cin>>choice;
        getchar();   //增加该语句,读走回车符
        if( choice>=0 && choice <= 3 )         
            switch(choice)
            {
                case 1:IntputStu(array);break;
                case 2:cout<<"Intput the name searched"<<endl;
                       char na[20];
                       cin>>na;
                       int i;
                       i=SearchStu(array, na);
                       if(i==N)cout<<"查无此人!\n";
                       else array[i].output();
                       break;
                case 3:OutputStu(array); break;
                default:break;
            }
    }while(choice);

    return 0;
}


void menu()     //显示菜单函数
{
    cout<<"**********1.录入信息**********"<<endl;
    cout<<"**********2.查询信息**********"<<endl;
    cout<<"**********3.浏览信息**********"<<endl;
    cout<<"**********0.退    出**********"<<endl;
}

void OutputStu( Student *array)             //输出对象数组元素
{
    cout<<"学生总人数="<<Count<<endl;
    for(int i=0 ; i<Count ; i++)
        array[i].output();
}

int SearchStu( Student *array, char *na )   //按姓名查询
{
    int i,j=N;  //设置j的初值为N

    for(i=0 ; i<Count ; i++)
        if( strcmp( array[i].getname() , na) == 0 ) j=i;    //记录下标值

    return j;   //返回下标值
}

void IntputStu(Student *array )                //输入对象数组元素
{
    char ch;
    do
    {   
        array[Count].intput();
        Count++;
        cout<<"继续输入吗?(Y or N )"<<endl;
        cin>>ch;
    }while(ch=='Y');    
}

1>e:\编程仓库\2号仓库(c++)\大实验2号\大实验2号\identify student.cpp(62): error C2084: 函数“Student::~Student(void)”已有主体
1> e:\编程仓库\2号仓库(c++)\大实验2号\大实验2号\identify student.h(19) : 参见“{dtor}”的前一个定义
1> 正在生成代码...
1>
1>生成失败。
1>

  • 写回答

1条回答 默认 最新

  • shanql 2019-03-31 23:08
    关注

    是有两个,文件开始第3个函数就是析构函数,还有一个在Student::getage的上面

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题