Base and Derived classes: default constructors?

I'm trying to create a database using maps.
The default constructors for the base class and the derived class essentially add details to these maps. (Create an ID number, and take keyboard input for a name, Job Title, contact number, then store these in 3 maps <ID, Name>, <ID, Job Title>, <ID, ContactNo>. The destructor is then called).

Because it destructs after being called, it allows a piece of code like:
1
2
3
4
5
6
char Decision1='Y';
        while(Decision1=='Y'){
	Positions Ne1;	//	Create new record using default const.
	cout << "Would you like to add another record? [Y/N]" << endl;
	cin >> Decision1;
	};

Ne1 can be created multiple times without worrying about loss of data (The details for the object are stored in the maps independant of the class)

The derived class and base class should have separate databases - the derived class constructor stores Positions within the Organization, and the base class constructor stores employee records.

I'm trying to build up so that when an Employee record is added, the Positions database can be searched for the job title entered to see if it exists.

Problem is - when I call the Positions (derived class) default constructor, it calls the Employee (base class) default constructor first.

First - is it standard for a derived class to call the base class constructor first?
Second - if so, is there a workaround, or do I have to plan out my system again?
Last edited on
[code] "Please use code tags" [/code]
First - Yes
Second - Why are you using inheritance in the first place?
Last edited on
Adjusted - sorry about that;

My initial plan was to create a "database" base class; which the Employee and Positions would be derived from. Objects created under the Database class would be Employee_Database and Position_Database.

I was planning to store under each database a map of the form map<ID, Employee> and map<ID, Positions> using a template, but after checking this plan with a Supervisor. The Supervisor explicitly stated that Positions must be a class derived from Employee, and Employee is to be an abstract base class.

The idea of using a class to keep records makes sense to me - previously for databases I would use structs, but they aren't as secure as classes. I'm struggling to see where inheritance can fit in without being arbitrary.

My understanding is under the supervisors stipulation; a Position has it's own details, and could access an Employees details too (For example; the Employee allocated to the positions ID) but that's about as far as I can grasp. To me it seems like I could just another map - but that feels like a kludge.

To me; it doesn't seem to make sense that way round - the way I'm trying to create it, the Positions exist before the Employee is hired to fill it. An Employee shouldn't have to be "created" whenever a Position is added - the position could be vacant!

...I think it might be time for me to go and redesign the code structure
Topic archived. No new replies allowed.