With the defined function as…
void func (int a [3]) { ... }
I’d like to be able to pass a dynamic static array like so
func (new int [3] {1,2,3});
instead of…
int temp [3] = {1,2,3};
func(temp);
Is this possible with C++?
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.
If you have a C++11 compiler,
func (new int [3] {1,2,3});would work fine (but, remember that you are responsible fordeleteing the memory). With gcc, just pass the-std=c++11flag.However, look into
std::arrayso you don’t have to usenew:Example