Hi,
I have been working on a uni C++ project. I am presently using VS2010 . It is almost the end and now I am facing a strange problem.
I try to run my program in debug mode by pressing F5. It works fine. Then I try to run the program by pressing Ctrl + F5, and I get an exception at free.c (It gives an exception to vector.push_back).
Then, I try the release mode. I try to run the program from the cmd. Yesterday I remember it was giving an error even before reaching that part. Today it just happens to work completely well (even though the Ctrl + F5 problem is still there).
I tried to search and the most common problem seems to be uninitialized local variables. So I went to my solution file and turned up the warning level to 4 for each of my projects and I do not seem to have any uninitialized variable before the part where the ctrl + F5 gives problem. Is there a better way to check if there is no uninitialized variable (without actually having to go through the entire code? )
Could there be any other problems? I also found that it maybe because of uninitialized memory locations. From what I know, the code is using pointers only when it comes to class objects. Otherwise we stick to stack memory and we pass by reference always (except when we are passing the class object).
Thanks for your reply.
Regards,
Harsha
start without debugging (F5) and start with debugging (Ctrl + F5)
Started by harshareddy75, Oct 29 2010 03:59 PM
1 reply to this topic
#1
Posted 29 October 2010 - 03:59 PM
|
|
|
#2
Posted 30 October 2010 - 08:38 AM
Hi,
Can you please explain a bit what data type you are using vector for? Is that a vector for saving pointer for your class like vector<myclass *> myVector;
Normally, when you're using such kind of vector, you need to make sure you adding a valid heap pointer, and not adding a pointer by referencing a local variable which is in STACK, and is removed once function returns. A vector would try to free its storage by calling appropriate destructer and finally you get an error for free or delete.
Can you also post a bit of the code for us to have better understanding of your problem?
Munir
Can you please explain a bit what data type you are using vector for? Is that a vector for saving pointer for your class like vector<myclass *> myVector;
Normally, when you're using such kind of vector, you need to make sure you adding a valid heap pointer, and not adding a pointer by referencing a local variable which is in STACK, and is removed once function returns. A vector would try to free its storage by calling appropriate destructer and finally you get an error for free or delete.
Can you also post a bit of the code for us to have better understanding of your problem?
Munir
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









