[英]Declaring a vector of objects as a member of another class
Hi I'm looking to declare a vector of objects as a member of another class but I'm not quite sure how to do this. 嗨,我正在寻求将对象向量声明为另一个类的成员,但是我不确定如何执行此操作。 And also am I filling the vector correctly in the last function? 我也可以在最后一个函数中正确填充向量吗?
This is the class that I want to create a vector of 这是我要创建向量的类
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;
};
and I want the vector to be a member of this class 我希望向量成为该类的成员
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;
};
Here is what I have so far for my function 这是我到目前为止的功能
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;
}
Any help would be useful. 任何帮助将是有用的。
Without fully understanding how submit_order() works, I think you need something like this: 在不完全了解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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.