Typedef 中的 C++ 指针

标签 c++ pointers typedef

我是 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/

相关文章:

c++ - DirectX:将数组指针传递给顶点结构

c - 如何获取C中对象中所有字符串的长度

objective-c - 将 CFIndex 转换为 NSUInteger?

c++ - 如何转发声明依赖于变体定义的类,而变体定义又依赖于模板化类?

将 2D 数组复制到函数外部动态分配的 2D 数组

c++ - 这个语法是什么? C++

c - C中的数组 "implemented"如何?

c++ - 是否可以将实现模板特化定义为另一种类型的 typedef?

c++ - 从函数返回时的右值引用行为

java - 如何为 Java 应用程序调试 C++ dll