c++ 编译通过了 但是仍然不能执行
#include<iostream>#include<cstring>usingnamespacestd;classCEmployee{protected:char*Na...
#include <iostream>
#include <cstring>
using namespace std;
class CEmployee
{
protected:
char*Name;
int Salary;
public:
virtual int salary()=0;
};
class CManager:public CEmployee
{
private:
int Week;
public:
CManager(char*name,int week)
{
Week=week;
strcpy(Name,name);
}
int salary()
{
Salary=Week*2000;
return Salary;
}
};
void main()
{
int week;
char*name;
cout<<"please input name"<<endl;
cin>>name;
cout<<"please input week"<<endl;
cin>>week;
CManager manager(name,week);
CManager *pm;
pm=&manager;
cout<<"salary is"<<pm->salary()<<endl;
}
编译通过了 但是仍然不能执行 麻烦您了 展开
#include <cstring>
using namespace std;
class CEmployee
{
protected:
char*Name;
int Salary;
public:
virtual int salary()=0;
};
class CManager:public CEmployee
{
private:
int Week;
public:
CManager(char*name,int week)
{
Week=week;
strcpy(Name,name);
}
int salary()
{
Salary=Week*2000;
return Salary;
}
};
void main()
{
int week;
char*name;
cout<<"please input name"<<endl;
cin>>name;
cout<<"please input week"<<endl;
cin>>week;
CManager manager(name,week);
CManager *pm;
pm=&manager;
cout<<"salary is"<<pm->salary()<<endl;
}
编译通过了 但是仍然不能执行 麻烦您了 展开
展开全部
有两个地方需要修改:
1.
class CEmployee
{
protected:
char Name[30];//这儿不能只是一个指针,*Name你没给分配空间,又怎么能存字符串进去。
int Salary;
public:
virtual int salary()=0;
};
2.
一样的道理:
main函数中的
char *name;
cin>>name;
一样要改成:
char name[30];
cin>>name;
或者用malloc动态分配内存。
1.
class CEmployee
{
protected:
char Name[30];//这儿不能只是一个指针,*Name你没给分配空间,又怎么能存字符串进去。
int Salary;
public:
virtual int salary()=0;
};
2.
一样的道理:
main函数中的
char *name;
cin>>name;
一样要改成:
char name[30];
cin>>name;
或者用malloc动态分配内存。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询