I have to make a function under class record that returns a pointer person class data type. I am assuming that this means setting a person object to equal to the returned pointer person class type but in order to do that It looks like i need to make an overloaded = operator. Here is my code:
-------------------------------------

#include <string>
#include <iostream>
#include <ctime>
#include <fstream>
using namespace std;
class person{
      protected:
               string firstName, lastName;
               int age;
      public:
             string getFirstname(){return firstName;}
             string getLastName(){return lastName;}
             int getAge(){return age;}
             void setFirstName(string fname){firstName=fname;}
             void setLastName(string lname){lastName=lname;}
             void setAge(int yo){age=yo;}
             virtual void print()const{cout<<lastName<<", "<<firstName<<", age "<<age<<endl;}
             void operator=(person);
                  

};
void person::operator=(person p){this->firstName = p.getFirstname();this->lastName = p.getLastName();this->age = p.getAge();}

class patient: public person{
     private:
             string desease;
             int id;
     public:
            void setDesease(string illness){desease=illness;}
            void setID(int ID){id=ID;}
            void print()const{cout<<lastName<<", "<<firstName<<"; age "<<age<<"; desease: "<<desease<<"; id: "<<id<<endl;}
            
};
class doctor: public person{
     private:
             string specialty;
             int ssn;
     public:
            void setSpecialty(string proffesion){specialty=proffesion;}
            void setSSN(int SSN){ssn=SSN;}
            void print()const{cout<<lastName<<", "<<firstName<<"; age "<<age<<"; specialty: "<<specialty<<"; ssn: "<<ssn<<endl;}
            
};
class record{
      private:
              int id;
              person* pPtr;
      public:
             record(int ID){id=ID;}
             void setpPtr(person subject){pPtr=&subject;}
             int getID(){return id;}
             person getpPtr(){return *pPtr;}
};

int main () {
        
        person theDoctor;
        ;
        doctor myDoctor;
        int ssn, age, ID;
        ID=999;
        record myRecord (ID);
        string Fname, Lname, specialty;
        cout<<"enter fname:"<<endl;
        cin>>Fname;
        cout<<"enter lname:"<<endl;
        cin>>Lname;
        cout<<"enter age:"<<endl;
        cin>>age;
        cout<<"enter desease:"<<endl;
        cin>>specialty;
        cout<<"enter ssn:"<<endl;
        cin>>ssn;
        myRecord.setpPtr(myDoctor);
        myDoctor.setFirstName(Fname);
        myDoctor.setLastName(Lname);
        myDoctor.setAge(age);
        myDoctor.setSSN(ssn);
        myDoctor.setSpecialty(specialty);
        myDoctor.print();
        theDoctor = myRecord.getpPtr;
        system("pause");
        return 0;
        }

This specifically What was specifically asked for the HW: "A function to return the value of pPtr"

I have tryed making an overloaded operation....but i can't figure it out.

You don't need one as a shallow copy is okay. The compiler is complaining because you didn't put the () after myRecord.getpPtr .

You don't need one as a shallow copy is okay. The compiler is complaining because you didn't put the () after myRecord.getpPtr .

Oh right....i actually noticed that and fixed it....is there an edit button in this forum for posts i have made? Anyway it is still giving me the "no match for 'operator=' in 'theDoctor = (&myRecord)->record::getpPtr()'"

change it back to theDoctor = myRecord.getpPtr(); and it appears to work just fine. It doesn't need the operator= after all.

can any one send me C++ code for 2-3-4 tree insertion, deletion and search code plz...email snipped

Edited 6 Years Ago by WaltP: email snipped

Comments
Post in your own thread, and no.
This article has been dead for over six months. Start a new discussion instead.