Function with nameless parameter

Asked

Viewed 190 times

3

Why to declare a function with that signature?

void funcao1(Pessoa&);
void funcao2(Pessoa&,void*);

void XN_CALLBACK_TYPE UserCalibration_CalibrationComplete(xn::SkeletonCapability& /*capability*/, XnUserID nId, XnCalibrationStatus eStatus, void* /*pCookie*/)
{
    XnUInt32 epochTime = 0;
    xnOSGetEpochTime(&epochTime);
    .
    .
    .
}
  • You’re talking about the void*? Or are you talking about the parameters only having kind?

  • the void* and Pessoa&

  • But what are you seeing wrong with them? It’s normal. Tell me what your question is

  • Yeah, I want to know why the parameters only have the guy, the void* I get it. But Pessoa& I don’t understand

  • The reason is because the language has been defined like this, and someone needs to state in this way that the language allows. If you don’t have a specific question, it becomes difficult to explain.

1 answer

2


You are declaring two functions, both return nothing.

Both have a first parameter that will be one reference for a data of the kind Pessoa. This only exists in C++, not in C. Do not confuse with & used in variables that is a reference operator, i.e., it takes the memory address of the variable. Although the symbol is the same, the features resemble, are very different things. In C++ references are preferable to pointers where possible.

Do not confuse the parameter xn::SkeletonCapability& with the argument &epochTime in the line within the example function, they are very different things. In the context of the parameter and the position placed, it indicates that you are declaring a reference. In the context of the argument is having the compiler take the memory address of the variable to be used as argument and pass this address to the pointer that function xnOSGetEpochTime is waiting.

The second function also has a second parameter whose type is not defined. It is a joker.

This is not very common in C++, there are other ways to solve this. But this is a way to determine that the parameter can take anything. This form is more common in C.

This is a pointer to void, in a certain way can be read as a pointer to any data, of any kind. That is it is possible to pass anything to this parameter.

Note that this is just the declaration of functions and not their definition. In the definition it is necessary to put, in addition to the type of the parameter, a variable that will receive the data.

In the example placed in later edition shows that two parameters are being rendered unusable with comments. Probably they are not being used within the function, which would generate a Warning. Probably this was the way they used to not create the variable but still maintain the positions of the parameters.

  • Oh man, right. It makes sense. It’s just the & that got me confused. And I was also confused by the fact that the code I’m using declares the function and implements, but the way it’s up there. I think that’s why it got confused. I’m going to add a chunk of code there, just to make it clearer. Thanks @bigdown

  • 1

    I think the last paragraph that I put down now is your real doubt. Before I could not understand.

  • yeah, that’s exactly it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.