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

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -