Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma argsused
- #include <string>
- #include <iostream>
- #include <iterator>
- #include <map>
- using namespace std;
- struct TTest {
- int ID;
- string Name;
- string Show() { return to_string(ID) + " - " + Name; }
- };
- typedef map<string,TTest> TTestMapList;
- //TTestMapList TestList;
- TTestMapList& GetTestList() {
- static TTestMapList TestList;
- return TestList;
- }
- bool GetTest(string str, TTest& T) { // any changes made to T does not affect value in map
- TTestMapList::iterator it = GetTestList().find(str);
- bool res = (it != GetTestList().end());
- //TTestMapList::iterator it = TestList.find(str);
- //bool res = (it != TestList.end());
- if (res) T = it->second;
- return res;
- }
- int main() {
- TTest s, t { 1, "abc" };
- //TestList.insert( pair<string, TTest> ("5", t) );
- GetTestList().insert( pair<string, TTest> ("5", t) );
- if (GetTest("5", s)) {
- s.ID = 1985;
- s.Name = "Ahmed Mido Sayed";
- }
- cout << t.Show() << "\n";
- cout << s.Show() << "\n";
- int x; cin >> x;
Add Comment
Please, Sign In to add comment