+ 2

Why Does My Array Always Have 2 Members?

For some reason, even though the code creates a flexible array with 6 members, when I pass it as a parameter to the BAW Plot constructor, the this->contents always has 2 members. Why does this happen? How can I fix this? Can someone point me to an article about arrays as parameters in-depth? https://code.sololearn.com/c2Wiok5P0xOF/?ref=app

24th May 2018, 11:30 PM
fallOut015
fallOut015 - avatar
1 Réponse
+ 6
Using sizeof to find the array size within a function/class wherein the array is passed as a parameter, is error prone. The array decays to a pointer, and sizeof would return the pointer size. https://stackoverflow.com/questions/17590226/finding-length-of-array-inside-a-function Also, why do you call it a 'flexible array'? It's clearly a fixed size one. Try using std::vector in <vector>, which knows it's own size. std::vector obj = {1,2,3,4,5,6}; std::cout << obj.size();
24th May 2018, 11:49 PM
Hatsy Rei
Hatsy Rei - avatar