我是 C++ 的新手,我先阅读 C++ Primer 4th edition .它有一个部分解释了指针和 Typedef,从下面的代码开始。
typedef string *pstring;
const pstring cstr;
我知道在我定义 typedef string *pstring;
之后我可以使用 *pstring
在我的代码中声明字符串变量。
<del>*pstring value1; // both of these line are identical,<br/>
string value2; // value 1 and value2 are string</del>
本书继续const pstring cstr1;
和 *const string cstr2;
是相同的。我不明白为什么它们是相同的声明?
最佳答案
它们并不相同。
pstring v1; // declares a pointer to string
string v2; // declares an object of type string
string* v3; // this is the same type as v1
关于Typedef 中的 C++ 指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7857230/