C++ inheritance help

Good morning folks!

I was following along with Ivan in his video on inheritance and I cannot get the ‘ivan.printSalary()’ to work. It says ’ class Person has no member named printSalary? but its not even in Person class. It is a member of Employee. can someone please enlighten me on what is wrong. I have went over the code and even rewrote it multiple times to come to the same issue. thanks in advance!

#include
using namespace std;

class Person
{
private:// variables should always be private

int age;
string gender;
int height;

protected:
string name;

public:

Person (string n, int a, string g)//construct
{
    cout << "CONSTRUCTING OBJECT!";
    name = n;
    age = a;
    gender = g;

    height = 100;
}

void printInfo()
{
    cout << "The name of the person is "<< name << endl;
    cout << "The age of the person is "<< age << endl;
    cout << "The gender of the person is "<< gender << endl;
    cout << "The height of the person is "<< height << endl;
}
void setHeight(int h)
{


    if(h>0)
    {
        height = h;
    }
    else
    {
        height = 0;
    }

}

int getHeight()// getter allows outside access to private variables
    {
        return height;
    }

};

class Employee : public Person{

public:
    int salary;
    Employee(string n, int a, string g) : Person(n, a, g){
        salary = 200;

    }

    void printSalary(){
    cout << "The salary of " << name << " is " << salary;

    }

};

int main()
{
Person ivan = {“ivan”, 22, “male”};
ivan.setHeight(66);
ivan.printInfo();
ivan.printSalary();

return 0;

}

You have to create an Employee object. Then you will have all the methods available to Person and Employee :slight_smile: