在下面的示例中,我想在每個TradingStrategy(1-N).cpp文件中創建本地覆蓋。有人能告訴我用C++實現這個最直接/最標準的方法嗎?如何實現類變種虛擬函數覆蓋
謝謝, 邁克
// TradingSide.h file
class BuySide: public CTradingSide{
public:
BuySide(CBMTTradingStrategy *p_Strategy, bool p_buySellSide, u32 p_spotInstIndex, u32 p_futInstIndex);
~BuySide();
virtual void onQuoteBuyExit(u32 p_instIndex);
virtual void onQuoteBuyEntry(u32 p_instIndex);
virtual void onFIXBuyEntry(u32 p_orderIndex, bmt_eng_events_t p_orderEvent);
virtual void onFIXBuyExit(u32 p_orderIndex, bmt_eng_events_t p_orderEvent);
virtual inline bool isBuyEntryCriteriaSatisfied(bmt_price_t &p_spotCash, u32 &p_buySpotQty );
};
class SellSide: public CTradingSide{
public:
SellSide(CBMTTradingStrategy *p_Strategy, bool p_buySellSide, u32 p_spotInstIndex, u32 p_futInstIndex);
~SellSide();
virtual void onQuoteSellExit(u32 p_instIndex);
virtual void onQuoteSellEntry(u32 p_instIndex);
virtual void onFIXSellEntry(u32 p_orderIndex, bmt_eng_events_t p_orderEvent);
virtual void onFIXSellExit(u32 p_orderIndex, bmt_eng_events_t p_orderEvent);
virtual inline bool isSellEntryCriteriaSatisfied(bmt_price_t &p_spotCash, u32 &p_sellSpotQty );
};
// TradingStrategy1.h file
class Trading1Class: public ParentClass{
...
SellSide *mySellSide;
BuySide *myBuySide;
}
// TradingStrategy1.cpp file
Trading1Class::BuySide::onQuoteBuyExit(u32 p_instIndex)
{
...
}
// TradingStrategy2.h file
class Trading2Class: public ParentClass{
...
SellSide *mySellSide;
BuySide *myBuySide;
}
// TradingStrategy2.cpp file
Trading1Class::BuySide::onQuoteBuyExit(u32 p_instIndex)
{
...
}
執行什麼?如何編寫執行交易交易的功能? –
您可以在每個Trading(1-n)類中創建嵌套類,並且可以擴展BuySide/SellSide。 I.e:Trading1Class:public ParentClass {... class MySellSide:public SellSide {onQuoteBuyExit(u32 p_instIndex){...}}; }; –
沒有「局部重寫」這樣的東西,你不能爲同一個方法編寫不同的主體,但是在重新設計之後,它應該有可能實現你的目標(我認爲虛擬方法將是最合適的)。 – Inspired