zoukankan      html  css  js  c++  java
  • Pointer

    1. const pointer

    pointer to const -> 指向的数据不能被修改

    const pointer -> 指针的地址不能被修改

    ====================================================

    int a = 3;

    int b = 4;

    // read from right to left
    const int * p1 = &a; // a pointer to a const int
    int * const p2 = &b; // a const pointer to an int

    *p1 = b; // not OK
    p1 = &b; // OK
    a = 4; // OK: *p1 = 4

    p2 = &a; // not OK
    *p2 = a; // OK

    ===================================================

    2. smart pointer

    A smart pointer is an abstract data type that stimulates a pointer with additional funationality, such as auto memory deallocation, reference counting, etc. In practise it could be a wrapper around of a regular pointer and forwards all meaningfull operations to the pointer

    The simplest smart pointer is autr_ptr which are defined in header file <memory>

    ======================================

    template <class T> auto_ptr {

    public:
    explicit auto_ptr(T* p): auto_ptr(p){}
    ~auto_prt() {delete ptr;}
    T& operator*(){return *ptr;}
    T* operator->(){return &ptr;}
    private:
    T* ptr;
    // other functionalities...
    };

    ====================================

  • 相关阅读:
    博客园风格简单修饰(Do It Yourself)
    十大经典排序算法
    物流BOS
    算法设计
    牛客网刷题
    关于上网的问题
    Lucene&Solr
    SSM综合练习
    四十八:WAF绕过-权限控制之代码混淆及行为造轮子
    四十七:WAF绕过-漏洞发现之代理池指纹被动探针
  • 原文地址:https://www.cnblogs.com/szzshi/p/7685467.html
Copyright © 2011-2022 走看看