Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,
Recently i've found strange error;

class ca
{
public:
int m_a;
};

class cb
{
public:
vector<ca> m_v;
};

CArray<cb, cb&> my_arr;
ca ca_elem;
cb cb_elem;
my_arr.Add(cb_elem);
my_arr.Add(cb_elem);
my_arr[0].m_v.push_back(ca_elem);  //this line causes crash, 


i can't catch here any kind of exception and i don't know why error occurs.
I suppose that this is related with vector's memory allocation but i don't understand why.

Error occurs only on release.
There is CArray because it is old project, now i try to use stl containers

Can anyone explain why this error occurs?

Regards
Posted
Updated 12-Jan-16 20:07pm
v3
Comments
CPallini 12-Jan-16 8:48am    
As it stands, it cannot crash, in my opinion. What about posting the actual code?
Albert Holguin 12-Jan-16 15:03pm    
Yep, I'll have to second CPallini... don't think that would crash as written in the post.
Sergey Alexandrovich Kryukov 12-Jan-16 10:45am    
As to the exception, how did you try to catch it?
—SA
Aescleal 12-Jan-16 17:26pm    
Does the code you've presented work when it's the only code in the program? i.e. wrap it in int main() with the relevant includes and see what happens.

What compiler are you using?

Are there any weird and wonderful macros kicking about that might confuse things (e.g. MS are very fond of redefining new in MFC in debug versions)?

Does adding an explicit copy constructor and assignment operator in the contained classes do anything?

Have you read the source code for CArray to see if you can get a handle on what's happening? (It's ghastly BTW)
Albert Holguin 12-Jan-16 23:23pm    
...although the purpose of redefining new in debug mode is to prevent this type of crashing for debugging (detect overflows/ invalid memory access)... so I doubt that's the cause of a crash.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900