Getting a ancestor to save derived class info

This is a discussion on Getting a ancestor to save derived class info within the C++ Programming forums, part of the General Programming Boards category; I am trying to get an ancestor array to save the info of a derived class. Maybe I am going ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    80

    Getting a ancestor to save derived class info

    I am trying to get an ancestor array to save the info of a derived class. Maybe I am going abou this the wrong way. Here is what I am working on. Person is the base class, employee is the decendant ot Person, and secure is a decendant of Employee. ( Theres more decendants but this is probably enough). Now I have all the function definitions in my code on my PC. My question is I am looking to store the info of Secure( level of access) into an Employee array so i dont need to make more than 1 array. As always, thank you all for any help that you can offer.


    Code:
    class Person
        {
        public:
         
         Person();
         ~Person();
        virtual void InFirstName();
        virtual string ReturnFirstName(); 
        
        virtual void InLastName();
        virtual string ReturnLastName();
    
        protected:
        
         string FirstName;
         string LastName;
        };
    
    class Employee:public Person
        {
        public:
        Employee();
        ~Employee();
    
        void InIDEmployee();
        int ReturnIDEmployee();
        Employee *PTR;
        private:
        int IDEmployee;  // a nine digit code
        
        };
    
    class Secure:public Employee
        {
        public:
        Secure();
        ~Secure();
        void InLevelOfAccess();
        int ReturnLevelOfAccess();
        
        private:
        int LevelOfAccess;
        };
    a piece of the assignment question:

    For this assignment, use C++ classes object-oriented design to create a program to help Global Tech Industries track employees and clients. You should create an abstract base class for a person that encompasses the common data of employees and clients, then create classes for employees and clients as descendants. Then, create classes for secure and support employees as descendants of employee. Finally, create structures to store and retrieve employees and clients, and a program that allows the user to interact with these structures.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I'm not quite sure what your question is. What do you want to make an array of, exactly? If all you need to store are LevelOfAccess (for some reason), then just make an array of ints and be done with it. If you need an array of people, then you can make an array of pointers to the base class and store that. (Although maybe we should be saying "vector" instead of "array" as well?)

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    80
    I am looking to store all the information about employees , there are different type of emplyees -secure and support. If i have 1 secure employee, and 1 support employee, is it possible to save the information(level of access) in an employee array so i can access both ?I hope i am not confusing you.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well, if I'm understanding your question, the answer is "yes and no". Yes, you can keep an array that has values that indicate types of employees (using ints or enums); no, that won't help you access your employees. If you store your employees in any even-slightly-reasonable way, you will not need any extra information at all to access your employees appropriately.

  5. #5
    Registered User
    Join Date
    Jul 2008
    Posts
    80
    I would like to store a Secure object (with levelofAcess) or Support (with PIN number) in an Employee object (it doesnt have access to LevelofAcess or PIN directly), so that I may save the information about all descendants of the Employee object without having to make 2 separate arrays to store the secure or support information.Is this possible? if so how can i acomplish this

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You can't store a Secure object or Support object in an Employee object. However, a pointer to an Employee can point to a Secure object or a Support object....

  7. #7
    Registered User
    Join Date
    Jul 2008
    Posts
    80
    ahh ok, i am beginning to see what u are saying. But how would i access the decendant info?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. derived class can not access base class protected member?
    By George2 in forum C++ Programming
    Replies: 2
    Last Post: 10-21-2007, 06:32 PM
  2. Inheritance: assign base class to derived class
    By MWAAAHAAA in forum C++ Programming
    Replies: 15
    Last Post: 01-22-2007, 03:31 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Replies: 4
    Last Post: 12-28-2002, 11:29 PM
  5. Troubles overriding a const in a derived class
    By sh0x in forum C++ Programming
    Replies: 5
    Last Post: 10-05-2001, 07:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21