I would question if inheritance is the right solution to this problem. While you could tweak it to work, it doesn't really make a lot of sense.
Inheritance implies an "is a" relationship. You might have an order for a Thingy or for a Box, but does that mean that a box
is an order?
Especially since Box has an array of thingys, does this mean your box is an order of 10 orders?
And then can you have an order of multiple items? What if a customer orders 3 Thingys and a Box? Would you have to create 4 different orders?
The approach I would take would be to have a different structure using "has a" relationships to tie the orders with what they're ordering, rather than "is a" relationships.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
class Order
{
...
list<Commodity*> items; // item(s) being ordered ("has a" relationship)
};
class Commodity
{
// abstract base class for items that can be ordered
};
class Thingy : public Commodity // "is a" relationship -- a Thingy is a Commodity
{
};
class Box : public Commodity
{
};
|
Then if you want different commodities to be shipped differently, you can have the commodity itself return the desired type of order:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
class Commodity
{
virtual Order MakeOrder()
{
// make a generic order
}
};
//-------------------
class Thingy : public Commodity
{
virtual Order MakeOrder()
{
// make an order specific to shipping 1 Thingy
// (use Postal Service or whatever)
}
};
|
As for your error.... it saying thingy being abstract typically means that there is a pure virtual function in Order that you did not give a body for in Thingy.