Passing arrays into functions(array decay to pointer)- prefer std::vector | Modern Cpp Series Ep. 28

preview_player
Показать описание


►Please like and subscribe to help the channel!
Рекомендации по теме
Комментарии
Автор

Excellent insights and clear presentations.

georgerochester
Автор

Great video as always. Very well explained. Thank You.

dhanushs
Автор

Thanks. You mentioned C libraries. That is a concern for some people. You may use some of the std::vector features to pass information to a C library especially if the use of library is const. In some cases, you can define a std::vector and use it directly 99% of the time. Next, the code can temporarily adapt for the C library function call without a defining a variable created as a plain C array. I have not seen your whole series. A plain array declared within a struct or class allows more traits to be passed.

videofountain
Автор

Amazing video! One question though. I understand that when passing the `std::array` type from the STL library to a function, we are required to specify the size of the array, as in `function(std::array<int, 5>)`. However, it raises the question of the purpose of this practice if we still have to explicitly indicate the size to the compiler. I envisioned that the advantage of using the array STL type would be expressed as follows: `function(std::array<int>)`, allowing us to work with a container that inherently knows its own size. I must admit that the necessity to specify the size remains somewhat bothersome when dealing with arrays in general.

default
Автор

sort of getting lost right here 9:00 because as far as I know, passByReference used when we are mutating data.
Whereas, here in the given timestamp, you said since we are not mutating data, we can use passByreference. Doesn't we should leave it as it is?(passByValue)

Clearing this confusion is highly appreciated. Thanks Mike! Great content though!

HetviP
Автор

hey mike, iam super new to programming and my question is that what is size_t?? i ve learned so much from this playlist. all thanks to you but i am so confused at this point what in the world is this? size_t and vectors

insadeyt
Автор

You have mentioned passing a vector to prevent this decay. Can we also pass an int array reference int& arr[] will that prevent the decay? Will the compiler just swap the reference with the array that is being passed when the function is called?

tamoghnobanerjee
Автор

vector is too expensive. Use std::span

didgerihorn
join shbcf.ru