I have an interface, let's call it Creature
, who has virtual functions that cause it to be abstract.
I have child classes of this interface such as Dog
, Cat
, and Pig
.
The compiler doesn't seem to like the following line due to not being able to declare variable thing
to be of abstract type Creature
.
Creature thing = Dog();
I know I can't instantiate interfaces and the like, but this is just a Dog
being declared as a Creature
.
I need some way of having one declaration work for all the children (i.e., being able to put Dog()
, Cat()
, or Pig()
where Dog()
is in the line above).
Can this be done in c++ or am I misusing inheritance and interfaces completely?