C++ cast

c++.static&const
1.static
static change the field and the life circle
a. variable with static in the file, this variable could only used in this file. 
b. variable with static in the function, the variable will exist till then program end rather then the end of the function.
c. variable with static in the class, this variable will belong to the class rather than the object.
2.const change the variable or the object


C++.cast
1.static_cast
static_case<type-id>(expression),
change expression to typeid, with no runtime security checking.
it can be used as fellow
a.cast between parent and child.
child to parent (secure), parent to child (insecure)
b.for basic data type cast.
int to char etc.
c.void to some other type.
d.other type to void
2.dynamic_cast
dynamic_cast<type-id>(expession)
the "type-id" and "expession" should both be pointer type or reference.
it could be used as follows:
a.cast between parent and child,just like static cast
but it will be safer for cast from "parent" to "child". 
b. cast between different type.
c. cross cast, not used very often.
3. reinpreter_cast
reinpreter_cast<type-id>(expession)
a.cast a pointer to an int
b.cast an int to a pointer
4.const_cast
const_cast<type-id>(expession)
change the const or volatile attribute.


volatile
a.volatile is a type specifier, for specifying the variable visited for different thread
b.tell the compile not the ommit it by compiling optimizing.
c.that's the program read the variable everytime visit it.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值