C++ – const error message

c++

what does this error message mean :
error C2662: 'addDoctor' : cannot convert 'this' pointer from 'const class Clinic' to 'class Clinic &'
I'm not using const though

sorry,but this is my first time posting experience

Clinic.h

class Clinic{
    public:
        Clinic();
        int addDoctor(Doctor*); 
    private:
        Doctor doctors[10];
        int d;
    };

Clinic.cpp

Clinic::Clinic()
    {d=-1;}
int Clinic::addDoctor(Doctor *x)
    {d++;doctors[d]=x;return d;} 

Best Solution

That means you are trying to call non-const member function addDoctor from a const member function.

EDIT: In the newly posted code, you have an array of Doctor objects but you are trying to put an pointer into that array. That will give an error like can not convert from Doctor* to Doctor

Related Question