The error of "} expected" appears at line 5.
Why is that? I have included it at line 12.

The error of "Declaration missing ;" appears at line 8.
Why? There is ";" at the end of the line.

class PEmployee
{
public:
PEmployee();
PEmployee(string employee_name, double initial_salary);
void set_salary(double new_salary);
double get_salary() const;
string get_name() const;
private:
Person person_data;
double salary;
};

int main()
{
PEmployee f("Patrick", 1000.00);
cout << f.get_name() << " earns a salary of "
<< f.get_salary() << endl;
return 0;
}

Have you defined constructors in line 4, 5 and these getter methods ?

Did you include <string> library before using string type?

Hi DeHF,
Post your complete code.

Hi DeHF,
In your code there is no definition for get_name() and get_salary() function, no initialization in constructor. I modified as below and its behaving fine as u expecting,

#include <iostream>
#include <string>

using namespace std;

class PEmployee
{
public:
    //PEmployee();
    string Name;
    double Salary;
    //Initialization of variable in constructor
    PEmployee(string employee_name, double initial_salary)
    {
        Name = employee_name;
        Salary = initial_salary;
    }
    void set_salary(double new_salary);
    double get_salary() const;
    string get_name() const;
private:
    //Person person_data;
    double salary;
};

//Function definition
double PEmployee:: get_salary() const
{
    return Salary;
}
//Function definition
string PEmployee::get_name()const
{
    return Name;
}

int main()
{
    //PEmployee f;
    PEmployee f("Patrick", 1000.00);
    cout << f.get_name() << " earns a salary of "
        << f.get_salary() << endl;
    return 0;
}
commented: Thank you for finishing his homework for him. Hope you get a good grade. -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.