Hello. Ive been doing c++ for a while but then suddenly i felt for trying Java also.
I came across interfaces in java and i liked them immedeatly.
I couldnt understand virtual classes in c++ earlier but, for some reason java felt simplier. But now i wanted to make a test to see if i could understand them. So i tried to throw them into an array. (Is this even possible to do?) Please check my code and see if you can solve it.
What i want them to do is first say their name then do their own doWork function. The name line shows, but nothing happends when i call Staff[i].doWork();
The C++ equivalent of a Java interface is more or less a class with all member functions being pure virtual. It's not possible to create an object of a class containing a pure virtual functions. The derived classes has to implement the function to make it not pure and therefore possible to create objects of the class. To make doWork a pure virtual function in staff you write void doWork() = 0;
If I remember correctly Java interfaces can't have member variables so I guess staff is more like an abstract class in Java (that is if you change doWork to pure virtual).
So to your real problem. Staff is an array of 4 staff objects. The type of the objects in the array is fixed and can't be changed. What happens on line 49 is that the staff copy constructor is used to construct the staff objects from the temporary grillMaster and Clerk objects.
staff pointers can point to staff objects but also to objects of classes that inherits from staff. So what you have to do is use pointers (or references, or smart pointers). staff* Staff[4] = {new grillMaster("Charles"), new grillMaster("David"), new grillMaster("John"), new Clerk("Bella")};