c++ 함수 디폴트 매개변수에 배열을 넣을 수 있나요?

삼구의신의 이미지

c++11 부터는 디폴트 매개변수로 구조체를 넣을 수 있던데
배열이나 포인터 같은것도 가능하나요?

익명 사용자의 이미지

int arr[] = {1,2,3};
void f(int array[] = arr, int *ptr = new int, std::vector<int> vec={1,2,3}) {}

이런 방법들이 있습니다.
hankyu의 이미지

찾아보니 다양한 예제가 있네요.

void myFunction(int myArray[] = array)
{
    std::cout << "First value of array is: " << myArray[0] << std::endl;
    // Note that you cannot determine the length of myArray!
}

nullprt로 설정하는 방법도 있습니다.

void myFunction(int myArray[] = nullptr ) {
                             // ^^^^^^^
}

개인 블로그
https://codingcoding.tistory.com