Can I do this in C++ (if yes, what is the syntax?):
void func(string* strs) {
// do something
}
func({"abc", "cde"});
I want to pass an array to a function, without instantiating it as a variable.
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.
It can’t be done in the current C++, as defined by C++03.
The feature you are looking for is called “compound literals”. It is present in C language, as defined by C99 (with C-specific capabilities, of course), but not in C++.
A similar feature is planned for C++ as well, but it is not there yet.