object class help?

This was the question, I commented the part I need help. I was given the format of the classes. I was also asked to define the part I commented down below which I do not know how to do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Person { 
public:   
Person();   
Person(string pname, int page);   
void get_name() const;   
void get_age() const; 
private:   string name;   
int age; // 0 if unknown }; 

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; /* this is the part I don't get I tried a constructor and 
a few other things but how do I define this as it is private and 
within another class. If possible could you just write the correct constructor,
 or possibly the function to define this. I really need help idk what to
 do   */
double salary; };
Last edited on
#include <iostream>
class Person {
public:
Person();
Person(string pname, int page);
void get_name() const;
void get_age() const;
private:
string name;
int age; // 0 if unknown };
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;
}

!! Try adding parenthesis after the person_data(); !!

Its just my guess cause in visual studio it removes the red line under it when i wrote it like that. But I am not sure as I am just starting to learn classes too. I'm not that great at coding yet :P but it's just a guess. Lets see if that helps.
Topic archived. No new replies allowed.