I'm trying to use an algorithm in a function.
Should be very simple.
However, regardless of which algroithm I attempt to use, all of them cause the same error when used in a function.
E0304 no instance of overloaded function "std::begin" matches the argument list
E0304 no instance of overloaded function "std::end" matches the argument list
I am guessing there is some small change that needs to be made.
Code:#include <iostream> #include <algorithm> #include "bool_element_option_03.h" #include "storage.h" int main() { int arr_value[ELEMENTS]{ 1, 2, 9, 4, 5, 6, 7, 8 }; int arr_copy_value[ELEMENTS]; // array population for (int var_create_array_a = 0; var_create_array_a < ELEMENTS; var_create_array_a++) { arr_copy_value[var_create_array_a] = 0; } //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)); for (int output = 0; output < ELEMENTS; output++) { std::cout << "copied decimals: " << arr_copy_value[output] << std::endl; } bool_element_option_03(arr_value, arr_copy_value); return 0; }
Code:#ifndef _STORAGE_H #define _STORAGE_H #define WIN32_LEAN_AND_MEAN // ----------------------------------------------------------------------------------------------------------------------------------------------------- // Constants // ----------------------------------------------------------------------------------------------------------------------------------------------------- //----------------------------------------------- const int ELEMENTS = 8; //----------------------------------------------- #endif
If I take these alorgithms out of the function and put them in main(), they work as they should.Code:#include <iostream> #include <algorithm> #include "storage.h" void bool_element_option_03(int arr_value[], int* arr_copy_value) { 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)); for (int output = 0; output < ELEMENTS; output++) { std::cout << "copied decimals: " << arr_copy_value[output] << std::endl; } }
Should I intentionally overload this function (so I can use algorithms in it)?
Overloading this function is not my intnetion. I'm not calling it multiple times with different arguments. This function is only being called once.




Reply With Quote
