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?
原文:https://www.cnblogs.com/0-lingdu/p/12826153.html