const使用大全
来源:互联网 发布:php 商城开发哪个好 编辑:程序博客网 时间:2024/04/28 17:13
先看以下两个文章:
http://www.vckbase.com/document/viewdoc/?id=689
http://www.vckbase.com/document/viewdoc/?id=412
补充:
- #include <stdlib.h> //system()
- #include <iostream> //cout<<
- #include <memory> //auto_ptr<>
- using namespace std;
- class MyClass
- {
- public:
- int x;
- MyClass()
- {
- //void constructor
- }
- ~MyClass()
- {
- //destructor
- }
- int MyFunc( int* /*const*/ y )
- {
- *y = 20; // 改变外部变量的值 int MyFunc(const int *y ) or int MyFunc( int const *y ) 时报错
- x = *y ; // 改变类内部变量值 int MyFunc( int *y ) const 时报错
- y = &x ; // 改变传来的指针参数值 int MyFunc( int *y ) const or int MyFunc( int* const y ) 时报错
- return 0;
- }
- int MyFunc2( int /*const*/ &y )
- {
- y = 20; // 改变外部变量的值 int MyFunc2(const int &y ) or int MyFunc2( int const &y ) 时报错
- x = y ; // 改变类内部变量值 int MyFunc2( int &y ) const 时报错
- return 0;
- }
- };
- //-----------------------------------------
- void Fun()
- {
- //-----------------------------------------
- MyClass m;
- int z = 10;
- m.MyFunc(&z);
- printf("call MyFunc: z=%d, MyClass.x=%d/t/n",z,m.x);
- m.MyFunc2(z);
- printf("call MyFunc2: z=%d, MyClass.x=%d/t/n",z,m.x);
- return;
- //--------------------------------------------
- }
- void main()
- {
- Fun();
- system("pause");
- }
- //-----------------------------------------
- const使用大全
- C++ 之 Const 使用大全
- c中的const使用大全
- const使用大全,彻底掌握
- const大全
- const与extren大全
- const常用大全
- const用法大全
- const用法大全
- const用法大全
- const用法大全
- const用法大全
- const 的用法大全
- const 用法大全
- C++ const用法大全
- 使用const
- 使用const
- const使用
- JAVA程序访问C#的WebSevice
- Lotus Notes/Domino Notes.ini settings
- 2003,XP等ntldr启动与2008,vista等启动方式的同时在引导菜单中出现
- 2009年六大网络安全威胁:SQL注入攻击在列
- 在LINUX上实现NAPI
- const使用大全
- Linux下C语言编程基础(Makefile)
- 踏上地面的第1天
- 进程间通信2. 通信方式及各自特点
- Effective Java(2nd Edition) Item 46 for-each循环优于传统的for循环(译文)
- drcc.com notesini
- linux 文件的解压与安装
- 为什么IE6.0下面会有部分CSS不生效?
- 求高手指点