Question

I saw this in a class declaration and was curious what is means? I am thinking that is may be a way to declare that a char array will be a member but the size is not fixed and will take it as an argument but I am not sure.

char *flagstr(int);

Is this what it is?

Était-ce utile?

La solution

No, that is not what it is.

When you see a declaration like this inside a class

char *flagstr(int);

it declares a member function called flagstr which takes one argument of type int, and returns a pointer to character.

You can tell that you are looking at a function declaration, because there is a pair of parentheses after the name. It may be confusing, because the parameter name is omitted (C++ syntax rules do not require programmers to specify names of parameters in declarations; moreover, you can omit names of unused parameters in function definitions). Here is the same declaration that should look familiar:

char *flagstr(int flagValue);

Autres conseils

This is just a function declaration which takes an int as its input parameter and return type char *.

You're confused here mainly because you forget that, in a function declaration, input parameter names are not necessary (only their types are).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top