I am wondering if its possible to use a base class as parameter in function but when calling the function passing a derived class?
In .h file
class parent
{
virtual void foo();
}
class child_a: parent
{
void foo();
}
class child_b: parent
{
void foo();
}
in main.cpp
void bar(parent p)
{
// Doing things
}
int main()
{
child_a a;
bar(a);
return 0;
}
Or do i have to use overloaded functions? it there another way to do it?