|
发表于 2008-8-13 12:02:16
|
显示全部楼层
Post by MatthewGong;1392308
斑竹真是强呀!
我画蛇添足一下,写了个const_cast的常规用法。说实在的,我们这些用C++的同学要多了解一下标准C++中的新东西,头脑不要局限在VC6.0那个阶段。
- [matt@localhost tmp]$ cat const.cpp
- #include <iostream>
- using namespace std;
- void abc(const int & i)
- {
- int &n = const_cast<int&>(i);
- n = 100;
- }
- int main() {
- int i = 10;
- cout << " i value is " << i << "\n";
- abc(i);
- cout << " i value is " << i << "\n";
- return 0;
- }
- [matt@localhost tmp]$ g++ const.cpp
- [matt@localhost tmp]$ ./a.out
- i value is 10
- i value is 100
- [matt@localhost tmp]$
复制代码
abc本身的参数时const int & i,C++引用的本质还是传指针 |
|