I don't understand what you're trying to do in bool_element_option_03() above. You seem to be trying to access a 2-d array as a 1-d array??
If yes, then something like:
or:Code:void bool_element_option_03(const int(&arr_value)[ELEMENTS], int(&arr_copy_value)[ELEMENTS], int(&arr_elements)[ELEMENTS][SLOTS]) { std::copy(std::begin(arr_value), std::end(arr_value), std::begin(arr_copy_value)); std::sort(std::rbegin(arr_copy_value), std::rend(arr_copy_value)); const auto it { (int*)&arr_elements }; for (size_t i {}, ie { ELEMENTS * SLOTS }; i < ie; ++i) std::cout << it[i] << ' '; // std::cout << *(it + i) << ' '; std::cout << '\n'; std::cout << "\nReverse sorted:\n"; show(arr_copy_value); }
but this is 'c' like code and not considered 'good' C++ code.Code:const auto* it { (int*)&arr_elements }; for (size_t i {}, ie { ELEMENTS * SLOTS }; i < ie; ++i, ++it) std::cout << *it << ' ';
Also note that this memory 'hack' for treating a 2d-array as a 1-d isn't valid for std::vector and std::array.




Reply With Quote
