zoukankan      html  css  js  c++  java
  • object and ptr

    1,

    #include <iostream>
    #include <string>
    #include <vector>
    #include <memory>
    
    using namespace std;
    
    class fruit {
        public:
            int *idx ;
    };
    int prodoucer(vector<fruit> &xc);
    int prodoucer(vector<fruit> &xc) {
        int first=1;
        int second=2;
        fruit apple; 
        apple.idx = &first;
        fruit pear; 
        pear.idx = &second;
        xc.push_back(apple);
        xc.push_back(pear);
    }
    int main(int argc, char *argv[]) {
        vector<fruit> vi;
        int rlt = prodoucer(vi);
        cout << " out side the fun" << endl;
        cout << &vi[0] << " using " << *(vi[0].idx) << endl;//not 1
        printf("-------------
    ");
        cout << &vi[1] << " using " << *(vi[1].idx) << endl;// not 2
        return 0;
    }

    result

     out side the fun
    0x5560736e90 using -998566032
    -------------
    0x5560736e98 using 127

     cv::Mat:

    Mat类的构成
    构造函数
    Mat的构造函数用来实例化一个mat对象,因此需要给出相应的参数完成初始化就可以了。mat类给出的构造函数输入参数大致可以分为以下几种(各种给出的具体方式可能不同):矩阵尺寸、类型、矩阵数据值、步长。
    - 矩阵尺寸给出的是矩阵的大小(行列数),通常的方式有枚举形式([rows,cols])、向量形式(vector& size)、数组指针(int * size);
    - 类型就是之前定义的Array Type;
    - 矩阵数据值通常是一个指向矩阵的指针(int* data);
    - 步长也通常是一个数组指针(size_t * step)

    为什么Mat中的普通指针(uchar *data)能够被指向局部变量,但是我写一个类,指向局部变量,就被回收了呢?

  • 相关阅读:
    史上最强验证
    Yii2 return redirect()
    一次线上问题引发的思考
    一次前端体验优化
    RSA For PHP
    判断是否字符串是否是JSON
    过滤Xss
    Yii2 中日志的记录
    Yii2 中禁用csrf校验
    开始。
  • 原文地址:https://www.cnblogs.com/0-lingdu/p/12826153.html
Copyright © 2011-2022 走看看