CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 16 of 16
  1. #16
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: use of algorithms in function cause ERROR: no instance of overloaded function

    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:

    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);
    }
    or:

    Code:
    const auto* it { (int*)&arr_elements };
    
    	for (size_t i {}, ie { ELEMENTS * SLOTS }; i < ie; ++i, ++it)
    		std::cout << *it << ' ';
    but this is 'c' like code and not considered 'good' C++ code.

    Also note that this memory 'hack' for treating a 2d-array as a 1-d isn't valid for std::vector and std::array.
    Last edited by 2kaud; November 29th, 2022 at 06:32 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured