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))) 
  • Does `char& some_function(int& some_input);` look fine to you? – KamilCuk Apr 20 '20 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? –  Apr 20 '20 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. – KamilCuk Apr 20 '20 at 22:59
  • I have added the actual code, how does this function have no body? –  Apr 20 '20 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. – Cody Gray - on strike Apr 20 '20 at 23:01
  • Uhh. the code in the edit is completely different to the original code in the question. Are you saying you did not actually come across the original code ? – M.M Apr 20 '20 at 23:01
  • yes, the first coded is my way of understanding the style. How are the very different? –  Apr 20 '20 at 23:03
  • The `[N]` parts are significant – M.M Apr 20 '20 at 23:03
  • lol @ the original author starting with the template and then reverting to `#define` unnecessarily – M.M Apr 20 '20 at 23:04
  • (Some people (like (extra parentheses))). – Pete Becker Apr 21 '20 at 13:48

0 Answers0