Inheritance problem!!!

I have a little problem here maybe someone could help me please. I have to provide a Programmer class which is a sub class of both Person class and the Staff class. I have done simple inheritance but I dont know much about multiple inheritance. Can anyone please help me with the assignment operators and their implementation. Here are the Person.h and Staff.h file:

Person.h

#ifndef __PERSON_H
#define__PERSON_H

class Person{
Protected:
char* name;
int age;

Public:
Person(char*, int);
Person(const Person&);
Person& operator=(const Person&); //???
~Person();
char* getName();
int getAge();
};
#endif

&&&&&&&&&&&&&

Staff.h

#ifndef __STAFF_H
#define__STAFF_H
class Staff{
Protected :
Char* post;

Public:
Staff(char*);
Staff(const Staff&);
Staffoperator=(const Staff&); //???
`Staff();
char* getPost();
};
#endif

Comments

  • Here is a hint to get you started. Note the checks for NULL to prevent your program from crashing.

    [code]
    class Person{
    protected:
    char* name;
    int age;

    public:
    Person(char* nm, int a)
    {
    if(ns != NULL)
    {
    name = new char[strlen(nm)+1];
    strcpy(name,nm);
    }
    else
    name = NULL;
    age = a;
    }
    Person(const Person&);
    Person& operator=(const Person& psn) //???
    {
    if(name != NULL)
    {
    delete[] name;
    name = NULL;
    }
    if(psn.name != NULL)
    {
    name = new char[strlen(psn.name)+1];
    strcpy(name,psn.name);
    }
    age = psn.age;
    }
    ~Person();
    char* getName();
    int getAge();
    };
    [/code]

  • Hi
    Thanks for the reply, it is very helpful. Thanks


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories