Search code examples
c++arraysparametersinline

initialize integer array inline when passing arguments to a method


Is it possible to initialize an integer array inline when calling a method in c++ (avr-g++)?

This is what I tried:

A({2, 4, 8, 3, 6});

void A(int* b) {

}

And I got this error:

cannot convert '' to 'int*' for argument '1' to 'void A(int*)' cannot convert '' to 'int*' for argument '1' to 'void A(int*)'


Solution

  • Looking at my old question I figured out I actually know the answer to this now. Here goes:

    void A(int *b) {
    
    }
    
    void foo() {
        A((int[]){1,2,3});
    }