-
const in function header
What are different possibilities that a const can appear in a function header, and what does each one do? Also, is something like this is possible?
Code:
void foo(int *a, int *b)*c
{
...
}
If so then what does that *c do there?
Moreover, in the following case (which I know can happen):
Code:
struct my_struct
{
...
}*z;
What's the function of *z?
Any help is appreciated.
-
>> What are different possibilities that a const can appear in a function header,
It can make a parameter const, it can make a return value const, and if the function is a member function it can make the function const within a class/struct.
>> is something like this is possible?
No.
>> What's the function of *z?
It is the same as saying my_struct* z; which is to declare a pointer to my_struct variable named z.
-
> What are different possibilities that a const can appear in a function header, and what does each one do?
When the function is a member of a class or struct and it will not alter the state of said class or struct.
EDIT: Daved reply to this question is more complete, than mine
> If so then what does that *c do there?
it generates a compile-time error.
> What's the function of *z?
to also generate a compile time error :)
Kidding... creates a pointer to my_struct called z.
-