const 與typedef 共同聲明指針

在聲明指針的過程中,經常會遇到const  int * p 和int * const  p1等 分別代表着值不變和指針不變。當利用typedf時會產生一下問題


typedef   string *  str;

1.const  str  p;

2.srr const  p1;

 其中 const  str  p  並不是代表着值不變,兩者都代表着對指針不變的情況,犯錯誤的原因是將typedef 當做文本化的擴展了 。將str 等同於string*  了,導致理解的錯誤。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章