Is there a way to avoid writing std::vector<int> twice on lines such as these?
std::vector<int>* numbers = new std::vector<int>(7);
(Typedefs don’t count.)
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.
Yes. In C++11 only:
Here the type of
numbersis inferred by the compiler, and it turns out to bestd::vector<int>*which is what you’ve written in your code.But wait. Why would use
newin the first place?Do you have any strong reason for that? Most likely not. Use automatic object instead: