jeudi 26 mars 2015

Inheritance and Multiple Constructor


Okay so I have this person class.



#ifndef PERSON_H
#define PERSON_H
#include<string>

using namespace std;


class Person
{
protected:
string name;
int age;
public:
Person();
Person(string newname, int newage);
void SetName(string n);
void SetAGe(int a);
string GetName();
int GetAge();
};

#endif


And the following person.cpp file.



#include "Person.h"

Person::Person(string newname, int newage){

name = newname;
age = newage;
}


And this Employee.h and .cpp file



#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include<string>
#include "Person.h"
using namespace std;


class Employee : public Person
{
protected:
float payrate;
public:
//Member functions
Employee() : Person(){ payrate = 10; }; //Constructor
Employee(float newpay); //Constructor

void SetPayrate(float p);
float GetPayrate{ return p; }

#endif


#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include<string>
#include "Person.h"
using namespace std;


class Employee : public Person
{
protected:
float payrate;
public:
//Member functions
Employee() : Person(){ payrate = 10; }; //Constructor
Employee(float newpay); //Constructor

void SetPayrate(float p);
float GetPayrate{ return p; }

#endif


And this is supposed to be able to use this line of code Employee b("Jane", 21, 12.38);


To create an employee with the name Jane, age 21, and payrate of 12.38, but it says that there is no method of the matching arguments. Am I missing something basic? Thanks.




Aucun commentaire:

Enregistrer un commentaire