Initialiser list passed as function parameter for array

后端 未结 5 1362
醉梦人生
醉梦人生 2020-12-19 07:49

How do I make this work:

void foo(uint8_t a[]) { ... }

foo({0x01, 0x02, 0x03});

It gives me an error:

error: cannot conver         


        
5条回答
  •  囚心锁ツ
    2020-12-19 08:33

    You cannot. Just construct

    uint8_t a[] = {0x01, 0x02, 0x03};
    

    and call foo(a).

    Or just use std::array, that is probably better.

提交回复
热议问题