我正在尝试编译以下代码,但消息“没有匹配函数来调用'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);
}
};
答案 0 :(得分:3)
您必须添加{}
才能构建Booking
到push_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)
。