【发布时间】:2013-07-16 22:37:00
【问题描述】:
在下面的示例中,我想在每个 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。即:Trading1Class : public ParentClass { ... class MySellSide : public SellSide { onQuoteBuyExit(u32 p_instIndex) { ... }}; };
-
没有“本地覆盖”之类的东西,你不能为同一个方法编写不同的主体,但经过一些重新设计后,它应该可以实现你的目标(我认为虚拟方法会是最合适的)。
标签: c++ class variables virtual