c++ - Deleting an array works on CodeBlocks but not on Visual -


I am creating a square and at some point I make a delete call. This works in codeboxes and it is not in Visual Studio 2013.

I have in my class:

  private: bool sign; // 0 if positive, 1 if negative inte numbered; Int vectorSize; Int * number;   

Then I have this function:

  zero XXLint :: edit (const char * s) {// size this-> size = strlen (S); // Start Sign In (S [0] == '-') {This-> Icon = 1; S ++; } And if (S [0] == '+') +++; else this-> Sign = 0; Delete [] number; // Debugger here gives me an error // get vector size-> vector seas = it-> Number size / 4; // Allowed Memory - gt; Number = new int [it-> Vector]]; // Store the string in the number vector. Int place = it-> Vector shapes; Int current = it- & gt; Number size-1; While {location} {int aux = 0; For (Inti = 3; I> => & amp;;; & amp; ;; -; i--) If (current - i> gt; 0) aux = aux * 10 + s [ Current - i] - '0'; Present - = 4; This- & gt; Number [place -] = aux; }   

} I had read the article and it is really interesting: D but I do not believe where it comes from an error. Why is this error happening?

Check here:

  this-> Number = new int [this-> Vector]]; Int place = it- & gt; Vector shapes;   

For logic, assume that this-> vector size == 10. Therefore location is now value 10. However, you Do it in a loop:

  while (location) {// ... this->; [Location--] = aux; // out of bounds! }   

You are reaching this - gt; Number [10] This is a memory overwrite and no, it can not be deducted before using space, as it is later reduced, no pre-derivative.

When you compile a program on another compiler and then run the program, it detects that runtime errors, always question your code, make a difference Does not it work "compile" on the compiler X, or if it works on your computer and your friend's computer, but not the teacher or the customer's computer, always suspect that there is something wrong with your code if I There is a failure like smoke corruption.

Comments

Post a Comment

Popular posts from this blog

jasper reports - How to center align barcode using jasperreports and barcode4j -

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -