You can use polymorphism to achieve what you're trying to do: a pointer to parent can take a pointer to a child. It is important that we're talking about pointers though.
See the C++ example below (works similarly in most object oriented languages):
#include <iostream>
class Base
{
public:
int baseValue;
Base(int value) :
baseValue(value)
{ }
void virtual Print() const { std::cout << "baseValue: " << baseValue << std::endl; }
};
class Derived : public Base
{
public:
float derivedValue;
Derived(int baseValue, float value) :
Base(baseValue),
derivedValue(value)
{ }
virtual void Print() const override { std::cout << "baseValue: " << baseValue << "; derivedValue: " << derivedValue << std::endl; }
};
int main()
{
const int nItems = 4;
Base * items[nItems] = { new Base(1), new Base(2), new Derived(3, 3.1f), new Derived(4, 4.1f) };
for (int i = 0; i < nItems; i++)
items[i]->Print();
return 0;
}
Notice how the items array (of Base pointers type) can hold Base and Derived pointers just as well. When we call Print(), polymorphism allows the virtual function to be called on the derived class when it stands in for the base class.
Output
baseValue: 1
baseValue: 2
baseValue: 3; derivedValue: 3.1
baseValue: 4; derivedValue: 4.1