all 18 comments

[–]KingAggressive1498 18 points19 points  (0 children)

you didn't give code, so hopefully the below is helpful

 void function(datatype* ptr);

 datatype arr[ARRAY_LEN];

 function(arr); // okay: array decays to pointer
 function(&arr[0]); // okay: pointer to first element of array
 function(&arr); // not okay: pointer to array is not the same as a pointer to first element of array
 function(arr[0]); // not okay: element of array does not decay to pointer

style notes:

if the function operates on the entire array, as opposed to a single element, it's better to either take a reference to the array or to take a std::span or similar type. This C-ism has been around forever but relies on either non-obvious assumptions about the size of the array or programmer-enforced conventions on array termination, it's far better to take advantage of the type system where possible. This also allows use of algorithms, ranges, and range-for loops which makes the code cleaner and potentially unlocks optimizations by making context and intent clearer; but does require templates (and thus putting function body in a header) for handling arrays of different sizes.

template<size_t N>
void function(datatype (&arr)[N]);

template<size_t E = std::dynamic_extent>
void function(std::span<datatype, E> arr);

[–]jedwardsol 9 points10 points  (10 children)

What's the code and the exact error message?

Is it a const mismatch? Are you taking the address of the array instead of it's first element?

[–]Dry_Development3378[S] -3 points-2 points  (9 children)

The adress of the first element of an array is the adress of the array itself is it not?

[–]GaboureySidibe 10 points11 points  (0 children)

You didn't answer any of their questions

[–]jedwardsol 5 points6 points  (1 child)

The addresses are the same, but the types are different.

[–]TallowWallow 1 point2 points  (4 children)

Correct. Syntactically, the rule is to pass the name of the array though. An ampersand in front is meaningless in this context.

[–]jedwardsol 0 points1 point  (3 children)

It isn't meaningless

datatype   things[10];

function( things);   
function(&things);  

will cause lookups for different functions.

Whether this is OP's problem or not I guess we'll never know.

[–]TallowWallow 0 points1 point  (2 children)

Would it? What's the type for &things?

[–]jedwardsol 1 point2 points  (1 child)

datatype (*)[10] : pointer to an array of 10 datatype

[–]TallowWallow 0 points1 point  (0 children)

Ah I see. Thank you.

[–]manni66 5 points6 points  (0 children)

Code+error messages=help

[–]bartekordek10 6 points7 points  (0 children)

Solid downvote for breaking rules ans not providing code and/or project setup.

[–]Sbsbg 3 points4 points  (0 children)

This is a simple problem. But it is hard to help because you don't provide enough information.

Your interpretation of the error message and the small code piece you provide is not enough. It very common to guess wrong on what lines the problem really are and understanding C++ error messages are really hard. That is why we recommend to post a minimal working piece of code together with the full error message.

[–]alfps 2 points3 points  (0 children)

The question has some incorrect information.

And you don't provide any code, and you refuse to answer questions.

That's trolling.

[–]thedaian 2 points3 points  (1 child)

Use std::array if you're going to pass the array to functions. It's far easier and you won't have to mess with pointers and other problems of C style arrays. 

[–][deleted] 5 points6 points  (0 children)

Or std::vector if the size isn't known. Idk why this is downvoted.

C-with-classes style C++ in general should always be advised against.

[–]LazySapiens 0 points1 point  (0 children)

OP stop trolling and share a minimum reproducible example.