Make an array an optional parameter for a c++ function -
in c++, can make parameter optional this:
void myfunction(int myvar = 0);
how do array?
void myfunction(int myarray[] = /*what put here?*/);
the default argument must have static linkage (e.g. global). here's example:
#include <iostream> int array[] = {100, 1, 2, 3}; void myfunction(int myarray[] = array) { std::cout << "first value of array is: " << myarray[0] << std::endl; // note cannot determine length of myarray! } int main() { myfunction(); return 0; }
Comments
Post a Comment