c++ - Trouble calling the print function of a pointer -


I'm actually stumped from some homework. I'm working on I.

I am working on a function called "boxFactory", which gives an indicator of the box base class in the test class. The test class calls the print function with that indicator.

I'm trying to get check-box box printing before working on other types. However, when I run the code below, the exception is put on the BPTR-> print (OS) which reads:

"Unwanted exception to the assignment on 0x0091C512: 0xC0000005: Location of access violation 0xCCCCCCD0 Read. "

  box * Boxfitcher (four c, int w, int h) {box * b; If (C == 'C') {checker CB; B = & amp; Cb; B & gt; SetHeight (h); B & gt; SetWidth (W); Return b; } Return tap; }   

code snippet from the test class:

  box * bptr = boxFactory ('c', 5,3); // check print # 7 os.str (""); // Reset Output Holder BPTR- & gt; Print (os); T.test (os.str () == "xx x \ nx x \ nx x x \ n", "print 5x3 check box from factory");   

Print function from Derivative Checker category:

  Ostream & amp; Check Box: For Loop for Print (Ostream and OS) Constance {// HEIGHT (Int i = 0; i & lt; height_; i ++) {bool isX; // Current position is x or empty / second line starts if (i% 2 == 0) {isx = true; } And {isx = false; } // for loop for WIDTH (int c = 0; c & lt; width_; c ++) uses {if (isx)) // isx boolean {os & lt; & Lt; "X"; Isx = false; // oscilates between the spaces bool} else {os & lt; & Lt; ""; Isx = true; // oscilation continues}} OS & lt; & Lt; "\ N"; // attach new line after each line} Return OS; } 

You are returning an indicator in a local variable. This is an undefined behavior.

  if (c == 'c') {checker CB; B = & amp; Cb; B & gt; SetHeight (h); B & gt; SetWidth (W); Return b; }   

If you leave the function if but you return the address, then here cb gets out of range Using the results of this address in "Undefined Behavior" you want to allocate an object to the pile instead and then return it. Something like the bottom

  b = new check-box ();    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -