In a few places in the code I have a struct
definition that looks like this:
typedef struct tagNameOfStruct{
//some methods and members
}T_NameOfStruct, * PT_NameOfStruct, FAR LPT_NameOfStruct;
typedef struct tagNameOfStructLists{
//some methods and members
}T_NameOfStructLists, * PT_NameOfStructLists, FAR LPT_NameOfStructLists;
typedef pair<T_NameOfStruct, T_NameOfStructLists> CStructPair;
typedef map<T_NameOfStruct, T_NameOfStructLists> CStructMap;
Than I see that inside a method within a loop the following line of code
T_NameOfStruct instance;
T_NameOfStructLists listInstance;
m_MapInstance.insert(CStructPair(instance, listInstance));
//structMapInstance is a members of method class of type CStructMap
That instance is being inserted to data-structure which is used outside the scope of the function.It is passed to the data-structure by reference.
- Shouldn't instance die when we leave the function scope?
- What does the last line of the struct definition mean?
Edit ---- Why this is not a duplicate, please reopen---- : The * PT_NameOfStruct, FAR LPT_NameOfStruct in the struct definition are different from the question you guys linked too. Also there is the issue of the passing the instance by ref while it is defines on the method stack. The strange thing is that the code works so I'm wondering what I'm missing here. Why don't I get an exception while trying to access destroyed objects in a different function which iterates over the data structure. Still think it's a duplicate?