1

We have:

 private void function(ptr* data, const int size_of_data){
       std::sort(std::begin(data), std::end(data), floatcomparer);

Is this actually possible? Is there another way? Cause I get here an error: no instance of overloaded function ""std::begin" matches the argument types are: (float *). I know that we need the size for a fast sorting algorithm like std uses and ptr* doesn't deliver an included size. But shouldn’t there be a way cause I know how big the array is I'm pointing on?

4
  • 1
    public is not allowed in function definition. Commented Dec 29, 2016 at 11:04
  • true that, i'll edit Commented Dec 29, 2016 at 11:05
  • 1
    Neither is private. Please read en.cppreference.com/w/cpp/language/access Commented Dec 29, 2016 at 11:08
  • You can if you pass an array by reference to function template. Commented Dec 29, 2016 at 11:37

2 Answers 2

1

Your function signature is wrong and you're calling std::sort incorrectly, you want something more like:

void function(float* data, std::size_t size_of_data) {
    std::sort(data, data + size_of_size, std::less<float>());
}
Sign up to request clarification or add additional context in comments.

Comments

1
std::sort(arr, arr+ size, std::greater<float>());

where you can use pass float arr in this form

func(float[],int sz){...}

With this comparator you can sort it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.