質問

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

typedef string *qstring;
const qstring cstr

What type of cstr ? Thank

役に立ちましたか?

解決

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.

他のヒント

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 *
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top