首页 > 其他 > 详细

object and ptr

时间:2020-05-04 13:12:25      阅读:44      评论:0      收藏:0      [点我收藏+]

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;
}
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;
    printf("-------------\n");
    cout << &vi[1] << "using " << vi[1].idx << endl;
    return 0;
}

result:

out side the fun
Segmentation fault (core dumped)

why cv::Mat can?

object and ptr

原文:https://www.cnblogs.com/0-lingdu/p/12826153.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!