As the topic, I was confusing this question for two night.
I tried to use function build_BDDs to modify the value of map data structure outs, but the value printed inside the function is not the same as outside the function.
I changed the bool elements of struct map_Data to int type and had the same problem. I suspect I'm using the wrong pointer, but can't figure out what's wrong.
here is my codes.
#include <bits/stdc++.h>
using namespace std;
struct map_Data{
bool hi;
bool lo;
};
map<pair<int, int>, map_Data*> outs;
class MWVC{
public:
map_Data build_BDDs(map<pair<int, int>, map_Data*> & ins){
map_Data txt;
txt.hi = 1;
txt.lo = 0;
ins[make_pair(2,4)] = &txt;
cout << ins[make_pair(2,4)]->hi << ";" << ins[make_pair(2,4)]->lo << endl;
return * ins[make_pair(2,4)];
}
};
int main(){
MWVC ojb;
map_Data a;
a.hi = 1;
a.lo = 0;
outs[make_pair(1,2)] = &a;
if(outs[make_pair(1,4)]){
cout << outs[make_pair(1,4)]->hi << endl;
}
map_Data b = ojb.build_BDDs(outs);
cout << outs[make_pair(2,4)]->hi << ";" << outs[make_pair(2,4)]->lo << ";" << b.hi << ";" << b.lo << endl;
return 0;
}
and the result is
1;0
0;0;1;0
Thanks advance.