zoukankan      html  css  js  c++  java
  • C++笔记(一)

    关于const

    int i = 0;
    
    // 以下两种声明等同,int类型的常量
    const int a = 1;
    int const b = 1;
    
    // 指向常量int类型的引用
    const int &c = b;
    // 指向int类型的常量引用
    int &const d = i;
    // 指向常量int类型的常量引用
    const int &const e = a;
    
    // 指向常量int类型的指针
    const int *f = &a;
    // 指向int类型的常量指针
    int *const g = &i;
    // 指向常量int类型的常量指针
    const int *const h = &b;
    
    typedef int *type_int;
    // 以下声明等同,都是int类型的指针常量
    const type_int l;
    type_int const m;
    int *const n = &a;
    
    class Test
    {
    	int a;
    public:
    	void test()
    	{
    		cout << "hello" << endl;
    	};
    	// 常量成员方法:
    	// 1、不能修改成员变量;
    	// 2、不能调用非const方法;
    	// 3、可以被其他成员方法调用;
    	void show() const
    	{
    		// error
    		test();
    		
    		// error
    		a = 2;
    
    		// correct, 可以读取成员变量的值,就像可以读取const对象的值一样
    		cout << a << endl;
    	};
    }
    


  • 相关阅读:
    批处理操作
    注册表操作
    js 表格操作(兼容模式
    asp解码.net传参
    windows+nginx 查看并发链接数
    windows+nginx负载测试
    开发cocos2dx真机插件遇到问题,以及心得
    react路由
    Redux实现原理解析及应用
    test
  • 原文地址:https://www.cnblogs.com/zhanghang-BadCoder/p/6476461.html
Copyright © 2011-2022 走看看