const question

Hi ,
I came across a function that is as

char* getdata( const char* const fedex ) ;

I am not able to get why use these two const in the function .
first const and second const .

what is the significant of these two const .
Thanks in advance .
The first one declares that the characters themselves are const; you can't change them.

Then second means that the pointer itself is const; you can't change what it is pointing at.
In fact the two declarations

1
2
char* getdata( const char* const fedex ) ; 
char* getdata( const char* fedex ) ; 


define the same function type. So the second declaration is redeclaration of the first declaration.

I can guess that const qualifier for the pointer in the original declaration is used to underline that fedex does not point to an array.
But what if i add char* getdata( const char* fedex) const ;
what is the significant of the last const .
closed account (zb0S216C)
A const following the parameter list indicates the function is read-only, and cannot modify the members of the class of which it's a member of. Of course, the function has to be a member of a class for it to be declared read-only. However, if a member is declared mutable, the function is allowed to modify it, regardless of its read/write privileges.

Wazzak
Last edited on
Thanks @Framework . what about const_cast does not it change the value of the member ?
Topic archived. No new replies allowed.