C
cmb99
I have a Symbol class, "MSFT". It has a bid and offer. "Dell" is also
an instance of such a class. Sometimes, though, I want to combine two
Symbol's into one, e.g. "MSFT" * "DELL", so that, I can do sym.bid()
and it returns the product of the two bids for an underlying
combination. How do I construct the class hierarchy?
class Symbol
{
public:
double bid() { return _bid; };
double offer();
private:
double _bid,
_offer;
};
ComplexSymbol : public Symbol
{
public:
ComplexSymbol();
~ComplexSymbol();
virtual double bid() {
return syms[0].bid() * syms[1].bid();
};
virtual double offer();
private:
double _bid,
_offer;
vector<Symbol> syms;
};
Or do I create a SimpleSymbol and ComplexSymbol all derived from an
ancestor? Basically I have objects which can have multiple parents.
an instance of such a class. Sometimes, though, I want to combine two
Symbol's into one, e.g. "MSFT" * "DELL", so that, I can do sym.bid()
and it returns the product of the two bids for an underlying
combination. How do I construct the class hierarchy?
class Symbol
{
public:
double bid() { return _bid; };
double offer();
private:
double _bid,
_offer;
};
ComplexSymbol : public Symbol
{
public:
ComplexSymbol();
~ComplexSymbol();
virtual double bid() {
return syms[0].bid() * syms[1].bid();
};
virtual double offer();
private:
double _bid,
_offer;
vector<Symbol> syms;
};
Or do I create a SimpleSymbol and ComplexSymbol all derived from an
ancestor? Basically I have objects which can have multiple parents.