coderchem 2017-06-14 00:21 采纳率: 100%
浏览 761
已采纳

指针数组和指针的区别。

#include
#include
#define N 10
using namespace std;
class Base
{
public:
int No;
int ID;
char Name[10];
char Sex[10];
char Birthday[10];
char Address[20];
int Phone;
void inputBase()

{ cout<<"输入员工的工作号:"< cin>>No;

cout<<"输入员工的姓名:"< cin>>Name;

cout<<"输入员工的性别:"< cin>>Sex;

cout<<"输入员工的身分证:"< cin>>ID;

cout<<"输入员工的生日:"< cin>>Birthday;

cout<<"输入员工的家庭住址:"< cin>>Address;

cout<<"输入员工的家庭电话号码:"< cin>>Phone;
}
void outputBase()
{
cout<<"工作号:"< }
};
class Personnel:public Base
{
public:
virtual void showper()
{
cout }
char Job[10];
int Pay;
void intputper()
{
cout cin>>Job;
cout<<"请输入该员工的薪水"< cin>>Pay;
}
void outputper()
{
cout<<"职务:"< }
};
//Personnnel *P[10];
//*P=new Personnal;*/
class Maintain:public Personnel //维修部
{
public: virtual void show()
{
cout }
};
void intsertper()
{
int n;
do
{
Personnel *p;
Personnel (*P)[10];
p=new Personnel;
p->showper();
p->inputBase();
p->intputper();
int q;
do
{

for(int i=0;i {
q=0;
if(P[i]==NULL)
{
break;
}
else if(P[i]->No==p->No)
{
cout<<"此工作号已存在!请修改~!"< p->inputBase();
p->intputper();
q++; break;
}
}

}
while(q!=0);
for(int j=0;j {
if(P[j]==NULL)
{
P[j]=*p;
cout break;
}
}
cout>n;
}
while(n==1);
}
void show()//显示数据

{
Personnel *p;
Personnel (*P)[10];
//cout< for(int j=0;j {
if(P[j]!=NULL)
{
p=P[j];
p->outputBase();

p->outputper();

}
}
}

int main()
{
int n;
cin>>n;
if(n=1)
{
intsertper();
}
else if(n!=1)
{
show();
}
return 0;

}
问题:
[Error] incompatible types in assignment of 'Personnel' to 'Personnel [10]'

  • 写回答

1条回答 默认 最新

  • 战在春秋 2017-06-14 00:49
    关注
     Personnel (*P)[10];  //定义了指针数组
    p=new Personnel;   //试图将一个指针变量赋值给数组
    

    这样操作不正确,可以这样:

    Personnel P;
    P = new Personnel;
    

    或者这样:

     Personnel (*P)[10]; 
    P[index]  =  new Personnel   // index可以是0-9中的某个整数,代表数组的第i个元素
    

    用心回答每个问题,如果对您有帮助,请采纳答案好吗,谢谢!

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

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?