Young111111234 2016-03-19 15:48 采纳率: 60%
浏览 1288

C++运行调试问题。。。。。


图片说明
#include "stdafx.h"
#include
using namespace std;

class Data_rec
{
public:
Data_rec()
{
name = NULL;
}
~Data_rec()
{
delete[]name;
}
void insert_name(char* pname)
{
delete[]name;
name = new char[strlen(pname) + 1];
strcpy_s(name,255, pname);
}
void print()
{
cout << "Name:" << name << endl;
}
private:
char* name;
};
////////////////////////////////////////////////////////////////////////

class Student :virtual public Data_rec
{
public:
Student() :Data_rec(){ id = NULL;}
~Student(){ delete[]id; }
void insert_id(char* pid)
{
delete[]id;
id = new char[strlen(pid) + 1];
strcpy_s(id,25, pid);
}
void print()
{
Data_rec::print();
cout << "ID:" << endl;
}
private:
char* id;
};
///////////////////////////////////////////////////////////////////////////////////////

class Teacher :virtual public Data_rec
{
public:
Teacher() :Data_rec(){ sal = 0; }
void insert_sal(float psal){ sal = psal; }
void print()
{
Data_rec::print();
cout << "Sal:" << sal << endl;
}
private:
float sal;

};
///////////////////////////////////////////

class Postgrad :public Student
{
public:
Postgrad() :Student(){ dn = NULL; }
~Postgrad()
{
delete[]dn;
}
void insert_dn(char* p)
{
delete[]dn;
dn = new char[strlen(dn) + 1];
strcpy_s(dn,25, p);
}
void print()
{
Student::print();
cout << "Dept name:" << dn << endl;
}
private:
char* dn;
};
/////////////////////////////////////////////

class Tpost :public Teacher, public Postgrad
{
public:
Tpost(): Teacher(), Postgrad(){}
void print()
{
Teacher::print();
Postgrad::print();
}

};

int main()
{
Teacher t;
Tpost tp;
t.insert_name("Li Min");
t.insert_sal(5000);
tp.insert_name("zhang jun");
tp.insert_sal(1500);
tp.insert_id("08901");
tp.insert_dn("computer");
t.print();
tp.print();
return 0;
}
今天学习C++时遇到的,编译是成功的,但运行时会出现异常。这是课本上的程序。请各位大神帮忙看看是什么问题。谢谢啦

  • 写回答

2条回答 默认 最新

  • devmiao 2016-03-19 15:52
    关注

    课本上的程序也不对,应该是指针的问题,点中断,仔细检查出错的行

    评论

报告相同问题?

悬赏问题

  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题
  • ¥20 关于#qt#的问题:Qt代码的移植问题