How can I push_back a struct into a vector?
struct point {
int x;
int y;
};
std::vector<point> a;
a.push_back( ??? );
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Or if you’re allowed, give
pointa constructor, so that you can use a temporary:Some people will object if you put a constructor in a class declared with
struct, and it makes it non-POD, and maybe you aren’t in control of the definition ofpoint. So this option might not be available to you. However, you can write a function which provides the same convenience: