Hi,
I am stuck trying to figure out how to include a class within a class and how to properly call members of a class from the main(). I cannot figure out what these error messages mean. I would greatly appreciate and insight into my dilemma. Thank You, C.D.

Enclosed is the last attempt I made with the project.

// PEmployee header
#include <string>
#include "Lab10.h"
using namespace std ;

class PEmployee
{
public:
    PEmployee() ;
    PEmployee(string employee_name, double initial_salary) ;
    void set_salary () const ;
    double set_salary(double new_salary) const ;
    string get_name() const ;
    void read_salary() ; 

private:
    person person_data ;
    double salary ;
    string name ;
} ;

// person header
#ifndef Lab10
#define Lab10
#include <string>
using namespace std ;

class person
{
public:
    person()    ;
    person( string pname, int page ) ;
    string get_name() const ;
    int get_age() const ;
    void read_name() ;
    void read_age() ;

private:
    string name ;
    int age ;
} ;
#endif

// person definitions
#include <string>
#include "Lab10.h"
using namespace std ;

class PEmployee
{
public:
    PEmployee() ;
    PEmployee(string employee_name, double initial_salary) ;
    void set_salary () const ;
    double set_salary(double new_salary) const ;
    string get_name() const ;
    void read_salary() ; 

private:
    person person_data ;
    double salary ;
    string name ;
} ;

// PEmployee definitions
#include <iostream>
#include <string>
#include "Lab10.h"
#include "PEmployee.h"
using namespace std ;

PEmployee :: PEmployee()
{
    salary = 0 ;
}

PEmployee ::PEmployee(string employee_name, double initial_salary)
{
        salary = initial_salary ;
        name = employee_name ;
}

double PEmployee :: set_salary(double new_salary) const
{
    double salary = new_salary ;
    return salary ;
}

string PEmployee :: get_name() const
{
    return name ;
}

void person :: read_name()
{
    person next ;
    next.read_name ;
    string employee_name = next.name ;
}

void PEmployee :: read_salary() 
{
    double new_salary = 0 ;
    cout << "Please enter the salary for the person " ;
    cin >> new_salary ;
}

// attempt to call member function
void main()
{
    person next ;
    cout << next.read_name ;
    system("PAUSE") ;
}

Recommended Answers

All 3 Replies

Hi these are the errors I get:

Error 1 error C3867: 'person::read_name': function call missing argument list; use '&person::read_name' to create a pointer to member c:\users\admin\desktop\lab 10\lab 10\pemployee.cpp 63 1 Lab 10

Error 2 error C3867: 'person::read_name': function call missing argument list; use '&person::read_name' to create a pointer to member c:\users\admin\desktop\lab 10\lab 10\pemployee.cpp 91 1 Lab 10

When you call a function, you need a pair of parentheses. Thus it should next.read_name(), not next.read_name.

Also your read_name is infinitely recursive and can't possibly work. And all it does (other than overflowing the stack) is to write to a local variable that it then never uses - that can't be right.

Another problem is that read_name's return type is void, so you can't use it as an operand to << (or to any other operator or function).

In this code:

double PEmployee :: set_salary(double new_salary) const

{
    double salary = new_salary ;
    return salary ;

}

You are creating a local variable "salary" which will override the class member salary. IE, it won't set the instance member like you think. Remove the "double" declaration. There may be other, similar issues, but I don't have time right now to find them for you. :-)

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.