您好,我希望将对象向量声明为另一个类的成员,但我不太清楚如何执行此操作。我也在最后一个函数中正确填充向量吗?
这是我要创建
矢量的类class AggregatedQuoteType
{
public:
AggregatedQuoteType(double price, unsigned long volume);
double get_price() const;
unsigned long get_volume() const;
unsigned long get_number_of_orders() const;
private:
double newPrice;
unsigned long newVolume;
};
我希望矢量成为这个类的成员
class OrderBook
{
public:
OrderBook ();
void open (double tick_size, double tolerance, std::ostream &log);
void close ();
unsigned long submit_order (double price, unsigned long volume);
private:
PriceType order_tick_size;
PriceType order_tolerance;
};
这是我迄今为止的功能
unsigned long OrderBook::submit_order (double price, unsigned long volume)
{
AggregatedQuoteType newQuote(price, volume);
unsigned long number_of_orders = newQuote.get_number_of_orders();
std::vector<AggregatedQuoteType> newMyOrder;
if(price > 0 && volume > 0){
for (unsigned int i = 0; i < number_of_orders; i++){
newMyOrder.push_back(newQuote);
}
}
return 0u;
}
任何帮助都会有用。
答案 0 :(得分:1)
如果没有完全理解submit_order()的工作原理,我认为你需要这样的东西:
class OrderBook
{
public:
OrderBook ();
void open (double tick_size, double tolerance, std::ostream &log);
void close ();
unsigned long submit_order (double price, unsigned long volume);
private:
PriceType order_tick_size;
PriceType order_tolerance;
std::vector<AggregatedQuoteType> quotes_;
};
unsigned long OrderBook::submit_order (double price, unsigned long volume)
{
AggregatedQuoteType newQuote(price, volume);
unsigned long number_of_orders = newQuote.get_number_of_orders();
if(price > 0 && volume > 0){
for (unsigned int i = 0; i < number_of_orders; i++){
quotes_.push_back(newQuote);
}
}
return 0u;
}