Hi All,
Please look at the code below.
In set() fucntion, I am building a vector test_values. In this, I am pushing local block values. Which goes out of scope when function exits.
When control comes to onEvent(), I am able to extract exact values that I have pushed in set().
How is this working?
All local that I have pushed are out of scope, then how test_values vector is containing the right values.
thanks in advance.Code:/*******************************************************************************************/ class abc { public: set(); onEvent(); private: struct test { int a; char b; }; std::vector<struct test> test_values; }; void abc::set() { struct test st1; st1.a = 1; st1.b = 0; test_values.push_back(st1); st1.a = 2; st1.b = 1; test_values.push_back(st1); st1.a = 3; st1.b = 2; test_values.push_back(st1); } void abc::onEvent() { test_values[0].a; test_values[0].b; test_values[1].a; test_values[1].b; test_values[2].a; test_values[2].b; } /*************************************************************** ****************************/
Jack