Question

I saw this code in the book and thought a lot about this.

typedef string *qstring;
const qstring cstr

What type of cstr ? Thank

Was it helpful?

Solution

Well qstring is a typedef of string * - a pointer to string. The const in const qstring applies to the outermost type of qstring, so it applies to the pointer, which makes cstr have type string * const.

OTHER TIPS

Typedefs are not simple text substitution, so modifiers will never affect the insides.

cstr is a pointer to a string, and it is const. It is not a pointer to a const string.

Qualifiers (const is a qualifier) never penetrate a typedef.

So const qstring type is string * const and not const string *.

cstr has type

string * const

not

const string *
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top