0

My assistant professor class is derived from two classes : enseigner class (which derive from personal) and PHD student ( whiche derive from Student class and student class dervie from peronal) i get the following error

"request for member nci is ambiguous"

nci is a private member of 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";
        }
      }
user3136456
  • 31
  • 1
  • 1
  • 5
  • It is ambiguous because your assistant professor has two base sub-objects of type personal. However you forgot to ask a question. – Öö Tiib May 21 '14 at 14:07
  • the question is how to solve the error , it's a multiple inhertance! "request for member nci is ambiguous" – user3136456 May 21 '14 at 14:12

1 Answers1

0

This question: Diamond inheritance (C++) might help you understand what's going on. You're using a instance of a class that derives from Personal in two inheritance paths, hence includes two copies of nci. So, when simply referencing nci, your class instance doesn't know which copy of nci to use.

There are a number of techniques to deal with this, but they depend on your code structure. Consider reading up on multiple inheritance, diamond inheritance and virtual inheritance. Such structures are notoriously tricky to get right.

Community
  • 1
  • 1
djikay
  • 10,450
  • 8
  • 41
  • 52