I have a Constructor for a class Student like this:
Student(ISubject subject, IStudy study);
With ISubject and IStudy being abstract classes. I then created classes that inherited from the abstract class. (E.g Maths : ISubject and Calculus : IStudy)
When I want to pass in an object of the derived class into the contructor i get an error. How can I fix that?
Thanks in advance.
If your classes ISubject and IStudy are abstract classes, you cannot create objects of these types according to the rules of the language. But when you write
(ISubject subject, IStudy study)
it tells that you want pass objects of these types as function arguments, but it isn't possible since these objects cannot exist.
Probably the thing you should do is to write
(ISubject* subject, IStudy* study)
in the function declaration, which means that you want not objects themselves, but pointers to objects of this type to be passed to the function. It won't, from one side, tell that you want to pass the objects which a priori cannot exist; and from another side it will make it possible to pass derived classes' objects to this function using pointers, since pointer to a derived class is implicitly convertible to a pointer to a base class.