- 浏览: 718675 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (1042)
- 数据结构 (36)
- UML与设计模式 (42)
- c++ (87)
- rust (36)
- Qt (41)
- boost模板元编程 (43)
- Linux (77)
- 汇编 (4)
- 其它 (2)
- 烹饪 (3)
- unix c / socket (73)
- 软件工程 (4)
- shell (52)
- Python (37)
- c++ primer 5th(c++11) (22)
- 数据库/MySQL (27)
- 数据存储 (4)
- lisp (7)
- git (4)
- Utility (3)
- CDN与DNS (54)
- Http (53)
- php (7)
- nginx/lua/openresty (41)
- redis (11)
- TCP/IP (16)
- 互联网 (6)
- kernel (2)
- go (33)
- 区块链 (43)
- 比特股 (13)
- 以太坊 (23)
- 比特币 (23)
- 密码学 (10)
- EOS (53)
- DAG (1)
- docker (1)
- filecoin (7)
- solidity (64)
- ipfs (8)
- 零知识证明 (1)
- openzeppelin (3)
- java (1)
- defi (7)
最新评论
#include<iostream> using namespace std; int main() { int i = 0; const int constInt = 1; //constInt = 2; // 错误:向只读变量‘constInt’赋值 //int &intRef = constInt;//错误:将类型为‘int&’的引用初始化为类型为‘const int’的表达式无效 //int *intPtr = &constInt;//错误:从类型‘const int*’到类型‘int*’的转换无效 [-fpermissive] /* double d = 3.123; int &i = d;//错误:将类型为‘int&’的引用初始化为类型为‘double’的表达式无效 */ const double constDouble = 3.123; const int &constIntRef = constDouble; //上一行代码会被编译器转换为: const int temp = constDouble; const int &ri = temp; cout << "constIntRef:" << constIntRef << endl; cout << "ri:" << ri << endl; //从右往左读 const int* constIntPtr;//可以不初始化 constIntPtr = &constInt;//指针,指向的是一个整形的常量 //*constIntPtr = 0;//错误:向只读位置‘* constIntPtr’赋值 //int *const intConstPtr;//错误:未初始化的常量‘intConstPtr’ int *const intConstPtr = &i;//常量,整形指针(指向整形变量的常量指针:这个指针的只能赋值一次,它是一个常量) //int *const testIntConstPtr = &constInt;//错误:从类型‘const int*’到类型‘int*’的转换无效 [-fpermissive] //intConstPtr = 0;错误:向只读变量‘intConstPtr’赋值 *intConstPtr = 2; cout << "*intConstPtr:" << *intConstPtr << endl; const int* const constIntConstPtr = &constInt;//指向整形常量的常量指针 //int &r = 0;//错误:用类型为‘int’的右值初始化类型为‘int&’的非常量引用无效 const int &r = 0;//那么常量便是有效了 cout << "r:" << r << endl; int *intPtr = &i; *intPtr = 3; //intPtr = constIntPtr;//错误:从类型‘const int*’到类型‘int*’的转换无效 constIntPtr = intPtr; cout << "*constIntPtr:" << *constIntPtr << endl; } constIntRef:3 ri:3 *intConstPtr:2 r:0 *constIntPtr:3
发表评论
-
条件变量
2018-12-03 13:43 409#include <iostream> #i ... -
std::function
2018-08-12 19:23 420#include <iostream> #i ... -
emplace_back
2018-08-02 07:40 516https://blog.csdn.net/xiaolewen ... -
柔性数组
2017-09-20 09:53 444#include <iostream> #i ... -
rawsocket发送icmp包
2017-09-06 09:54 614#include <stdio.h> #in ... -
查看glibc版本
2016-12-07 14:13 492strings /lib64/libc.so.6 |grep ... -
trim
2015-05-14 14:45 319/* trim from start */ ... -
log
2015-03-30 17:42 410log.h #ifndef __LOG_H__ #def ... -
输出类名
2014-02-20 21:51 539#include <iostream> us ... -
GC的改良
2013-10-17 22:05 529分代回收:对分配不久,诞生时间较短的“年龄”对象进行重点扫描, ... -
GC与引用记数
2013-10-16 21:57 664根(Root)就是判断对象是否可被引用的起始点。至于哪里才是根 ... -
c++11应该使用的特性
2013-07-27 11:09 725http://blog.jobbole.com/44015/ -
random(new)
2013-07-21 12:00 757#include<iostream> #in ... -
tuple(new)
2013-07-15 22:11 553#include <tuple> #incl ... -
qtcreator c++11
2013-07-15 22:10 846在.pro里面:QMAKE_CXXFLAGS += -std= ... -
pthread
2013-07-09 10:10 551#include <pthread.h> # ... -
weak_ptr
2013-04-20 16:07 738unique_ptr(定义在中)提供了一种严格的语义上的所有权 ... -
shared_ptr(new)
2013-04-11 23:59 753#include <memory> #inc ... -
c++ lambda
2013-03-24 11:26 935#include <iostream> #i ... -
定长容器
2013-03-02 12:17 733#include<iostream> #in ...
相关推荐
const char* pCh; // 指向字符串常量的指针; 表示pch是一个指针,指向字符串常量。根据需要还可以指向另一个字符串。 但字符串不能被改变。 char* const pCh; // 指向字符串的常量指针; 表示pch是一个字符串常...
Const,Const函数,Const变量,函数后面的Const Const,Const函数,Const变量,函数后面的Const
C++:关于const的思考.doc onst的思考 1、什么是const? 常类型是指使用类型修饰符const说明的类型,常类型的变量或对象的值是不能被更新的。(当然,我们可以偷梁换柱进行更新:) 2、为什么引入const? const...
关于C语言中const的用法。以下摘自原文:In my last column, I discussed one of the reasons why the rules by which a compiler can place data into ROM are a bit more complicated in C++ than they are in C. ...
本文章是关于C语言中const定义常量 。
static,const,static const,const static是c++中几个常见的很容易弄混淆的几个概念,在这里总结了一下,与大家分享!
为了程序的健壮型,减少程序出错,这里详细介绍了const的用法。
Dan_Saks 关于C语言中有关const的含义和用法剖析的英文原版文章
易语言 常量支持库.1.6.版本const.fne
本文给大家介绍了C++中的const限定修饰符。
关于const的详细讲解,非常有用!!!!!!
C++中的各种Const用法小结:const常量,const 修饰类的数据成员等等
const int *a int * const a 区别 外加实例
const在C++中占有重要作用,属于小兵立大功的典型,本文档详细介绍了如何使用const
c语言之const用法 c语言之const用法 c语言之const用法 c语言之const用法 c语言之const用法
现在读到了const关键字的用法,书上面讲解的时候并没有给出完整的实例,只是理论的讲解了一些知识,后来在网上面搜了关于const的关键字的讲解,但是搜到的内容和书上面讲解的内容有着非常让人疑惑的东西,看看下面的...
一 const基础;二 const的初始化;三 作为参数和返回值的const修饰符;四 类成员函数中const的使用;五 使用const的一些建议。
该文档讲述了const与指针的关系,const起了如何的作用。
const和volatile分析 这个分析得很好 面试 找工作 必备的
C++中const关键字详解