I have a base class Device and inherited class InputDevice. In class XYZ I have a function XYZ::setDevice(int num, Device device) that expects object Device as parameter. When I call the function setDevice() with parameter that is sublclass of Device (InputDevice) it gets converted to Device and I can't access the derived functions of derived class afterwards. So if I want to call the function of "device" in function setDevice() it calls function of Device instead of overriden function in class InputDevice. What am I doing wrong?
void XYZ::setDevice(int num, Device device) {
printf("%s\n", typeid(device).name()); //this prints "Device"
this->devices[num] = device;
}
XYZ::XYZ() {
printf("%s\n", typeid(InputDevice(cin)).name()); //this prints "InputDevice"
setDevice(STANDARD_INPUT_DEVICE, InputDevice(cin));
printf("%s\n", typeid(devices[0]).name());
}