Passing array to a function (and why it does not work in C++)

后端 未结 7 1445
死守一世寂寞
死守一世寂寞 2020-12-15 15:03

I have come across some C code that compiles, but I do not understand why. Specifically, I have a C library that has a lot of code using this format:

void ge         


        
7条回答
  •  误落风尘
    2020-12-15 15:42

    The reason it works in C, but not in C++ is simply because it's C code and not C++. The two languages share a history, not a grammar.

    The C++ method to pass variable-sized arrays is std::vector, probably by reference if you intend to modify the vector in the function, or by const reference if you don't.

提交回复
热议问题