c ++向量推回课程

时间:2015-12-11 16:17:00

标签: c++ vector

我正在尝试编译以下代码,但消息“没有匹配函数来调用'std :: vector :: push_back(double&)'”继续出现。有人可以帮我解决吗?

struct Booking
{
   double bT;
   double aT;
   double dT;
};

class New
{
private:
    std::vector<Booking> vectorBookings;

public:

    void gB(double bR,double aR, double dR,double startTime,double finishTime)
    {
        double bT;
        do
        {   
            bT   = startTime   - (1.0/bR);
        } while(bT<finishTime);

        double aT   = bT - (1.0/aR);
        double dT = aT - (1.0/dR); 

        vectorBookings.push_back(bT,aT, dT);
    }  
};

2 个答案:

答案 0 :(得分:3)

您必须添加{}才能构建Bookingpush_back

vectorBookings.push_back({bT,aT, dT});

答案 1 :(得分:1)

如果您为Booking定义构造函数,则可以使用emplace_back

struct Booking
{
    Booking(double bT, double aT, double dT) : bT {bT}, aT {aT}, dT {dT} {}
    double bT, aT, dT;
};

然后只需将vectorBookings.push_back(bT, aT, dT)更改为vectorBookings.emplace_back(bT, aT, dT)