我的助理教授类是从两个类派生的: enseigner类(派生自personal)和PHD student (派生自Student类,学生类派生自peronal),我得到以下错误
“成员nci的请求不明确”
nci是personal的私人成员
enter code here
#include<iostream>
using namespace std;
#include "enseigneer.h"
#include "assistant_professor.h"
#include "associate_professor.h"
#include "professor.h"
void assistant_delete(assistant_professor**head_assis,assistant_professor **tail_assis)
{
int number;int pos=0;int sz=0;
assistant_professor *temp;
assistant_professor *search_1;
assistant_professor *current;
assistant_professor *to_free;
temp=*head_assis;
current=*head_assis;
cout<<"Enter the CIN number of the enseigner that you want to delete\n ";
cin>>number;
if(head_assis==NULL)cout<< "The list is empty you have to enter data first\n";
else
{
while (search_1!=NULL)
{
search_1=search_1->next;sz=sz+1;
}
if ((*head_assis)-> nci==number)
{
to_free=*head_assis;
(*head_assis)=(*head_assis)->next;
delete (to_free);
cout<< "\nThe student was deleted\n";
}
else if ((*tail_assis)->nci==number)
{
for (int i=0;i<sz-3;i++)
current=current->next;
delete(current->next);
current->next=NULL;
*tail_assis=current;
cout<< "\nThe enseigner was deleted\n";
}
else
{
{
while((temp!=NULL) and ((temp->nci)!=number))
{
temp=temp->next;pos=pos+1;
}
if (temp->next==NULL) cout<<"Please pay attention the enseigner you've entred doesn't exist in the list\n";
else
{
for (int i=0;i<pos-1;i++)
current=current->next;
to_free=current->next;
current->next=current->next->next;
delete(to_free);cout<< "\nThe enseigner was deleted\n";
}
}发布于 2014-05-21 22:10:07
这个问题:Diamond inheritance (C++)可能会帮助你理解所发生的事情。您在两个继承路径中使用了一个从Personal派生的类的实例,因此包含两个nci副本。因此,当简单地引用nci时,您的类实例不知道要使用哪个nci副本。
有许多技术可以解决这个问题,但它们取决于您的代码结构。考虑一下多重继承、菱形继承和虚拟继承。众所周知,这样的结构很难正确处理。
https://stackoverflow.com/questions/23785515
复制相似问题