c++ typedef的一些理解

TinnCHEN發表於2019-01-20

c++ typedef的一些理解

最近在看c++primer,在看到6.7章函式指標對typedef用法有些疑問,上半部分基本清楚了,下半部分還是有些疑問。
在書裡將typedef的章節部分沒有提及這種使用方法,不知道我加的註釋是否正確,如果有清楚的歡迎留言,不勝感激!

char a = 'a';
 const char b = 'b';
 typedef char * pstring;
 const pstring cstr = &a; //頂層const 相當於char * const pev,與const char * p 不同 //不能直接帶入理解
 const char * p = &b;     //底層const
 char * const pev = &a;  //頂層const

/////////////////////////////////////////////////

//正常宣告函式指標的方法是:
//eg:
int (*pf)(int a, int b) ;
//使用typedef可以直接將pf這個函式指標轉化為函式指標型別
typedef int(*pf)(int a, int b);
 vector<pf> v;

相關文章