0

I have come across the following code snippet in C++ and I have no idea what it means;

#include <iostream>

char (&some_function(int (&some_input)));  

int main ()
{
  // main code here 
  return 0;
}

How is some_function a function? what kind of syntax is this? where is the body? I'm sure this is only a C++ syntax as it doesn't compile in C.

Edit: Actual code with above style:

template <typename T, size_t N>  
char (&ArraySizeHelper(T (&array)[N]))[N];  
#define arraysize(array) (sizeof(ArraySizeHelper(array))) 
10
  • Does char& some_function(int& some_input); look fine to you? Commented Apr 20, 2020 at 22:57
  • yes, a function that returns a reference to a char and takes a reference to an int. Whats' with the extra brackets? where is it's body? Commented Apr 20, 2020 at 22:58
  • If so, then why are the extra brackets confusing? Whats' with the extra brackets? ask the person that has written the code. Now you have updated your post with a very different code. Commented Apr 20, 2020 at 22:59
  • I have added the actual code, how does this function have no body? Commented Apr 20, 2020 at 23:01
  • It doesn't compile in C because C doesn't have references. C++ does. It's just a function declaration, not a definition. You said as much in the title. Commented Apr 20, 2020 at 23:01

0