Item08. 多级指针(Pointers to Pointers)
来源:互联网 发布:猎聘 简历优化顾问 编辑:程序博客网 时间:2024/05/18 01:43
Item08. Pointers to Pointers
指向指针的指针(多级指针)与指针有相同的地方也有不同的地方
--------------------------------------------
1、改变指针的地址指向
void scanTo( const char **p, char c ) {
while( **p && **p != c )
++*p;
}
char s[] = "Hello, World!";
const char *cp = s;
scanTo( &cp, ',' );//指向","
2,优先使用指针的引用
void scanTo( const char *&p, char c ) {
while( *p && *p != c )
++p;
}
3,指针与多级指针的差别
1)指针能用于多态,而多级指针不可以
Circle *c = new Circle;
Shape *s = c; // 正确...
Circle **cc = &c;
Shape **ss = cc; // 错误!
2)加上const搅合后,非指针常量可以赋值给指针常量,但不可以赋值给多级指针
char *s1 = 0;
const char *s2 = s1; // 正确...
char *a[MAX]; // aka char **
const char **ps = a; // 错误!
- Item08. 多级指针(Pointers to Pointers)
- 指针的指针(pointers to pointers)
- 重新认识二级指针(Pointers to Pointers)
- 重新认识二级指针(Pointers to Pointers)
- Pointers to Functions 函数指针
- Pointers to Pointers
- Chapter 22: Pointers to Pointers
- SingleLinkNode with Pointers-to-Pointers
- [C++]C++ Pointers to functions 函数指针
- Pointers
- Pointers
- Pointers
- Pointers to Class Members Are Not Pointers(指向类成员函数的“指针”并非指针)
- Smart Pointers智能指针
- Dangling Pointers----悬挂指针
- 智能指针(Smart Pointers)
- Item07. 常量与指针的联姻(Const Pointers and Pointers to Const)
- Constant Pointers and Pointers to Constants
- 交行开始“清理门户” 28起金融案和上市豁免
- 使用C++模板技术实现类的动态注册和获取
- 最美的十大精典爱情句子
- sizeof,终极无惑(上)
- 抵制日货,现在做起
- Item08. 多级指针(Pointers to Pointers)
- Item09. 强制转换(New Cast Operators)
- 学习DotNet经典网站
- 中华人民共和国民法通则
- 中华人民共和国合同法
- Thread In Java Technology
- 中华人民共和国公司法
- 建设性冲突
- 基类一定要有默认构造函数