Something Conclusion in C++

Object

  • Most generally, an object is a region of memory that has type.

const Qualifier

  • "const type object" means object's type is type, and object is const. 由内而外的解析.
    Something Conclusion in C++Something Conclusion in C++const qualifier
int ivar = 2;typedef int *PI;// the type of pi is PI = (int*), and pi is constconst PI pi = &ivar;// pi is a pointer, the type of (*pi) is int, and (*pi) is constconst int *pi;// pi is const, pi is a pointer, the type of (*pi) is int, and (*pi) is constconst int *const pi = &ivar;
  • const reference

A const reference may be bound to an object of a different but related type or to an rvalue.


* Names defined outside any functions have global scope.

When we define a non-const variable at global scope, it is accessible throughout the program. Unless specified using extern, const variables declared at global scope are local to a file by default. (So const variables can be defined in header files.)

  • const member function

That 'const' modifies the type of the implicit 'this' parameter.
Something Conclusion in C++Something Conclusion in C++const member function

class A {public:    int m_ivar;    A():m_ivar(1024) {}    ~A(){}    int get() const {        return m_ivar;    }};int main(){    A insA;    // insA.get( const A *const this)    insA.get();    return 0;}

这样也就解释了:成员函数的重载需要考虑const或volatile,因为这样改变了隐藏参数this的类型。

array

  • sizeof 返回一个 ‘对象的类型’ 或 ‘类型名’ 的长度,长度的单位是字节数,sizeof表达式的结果是编译时的常量。
    原文链接: https://www.cnblogs.com/soulnearby/archive/2011/04/20/2022704.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/24298

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 上午2:08
下一篇 2023年2月8日 上午2:08

相关推荐