c++ - Seg fault in copy constructor -


I'm working on an assignment in which we compile "and then the call constructor is called. Here's where:

  Image :: Image (Constant Image and ImageTop) {fileType = imageToCopy.fileType; Width = imageToCopy.width; height = imageToppyHigh; MaxColor = imageToCopy.maxColor; Image = new int * [height]; for (int i = 0; i & lt; height; i ++) {image [i] = new int [width]; for (int j = 0; j & lt ; Width; j ++) {image [i] [j] = imageToCopy.image [i] [ja];}}}  

It is said: image2 (image1);

Why does this happen to some extent I am in loss, I do not know what is wrong because the code is similar to my Constructor, which works fine. The only difference is that I have

  image [i] [j] = imageToCopy Instead of  [j];   

  image intestream> gt;> image [i] [j];   

Thoughts? Thanks

Edit: Manufacturer is below:

  Image :: image (const char * filename) {ifstream imageInputStream; ImageInputStream.open (file name); Image Intestream & gt; & Gt; File type; Image Intestream & gt; & Gt; Width; Image Intestream & gt; & Gt; Height; Image Intestream & gt; & Gt; MaxColor; Image = new int * [height]; For (int i = 0; i  & gt; Image [i] [j]; }} ImageInputStream.close (); } Without seeing the complete code, this is just an estimate, but if you have 'we created a copy constructor and a destructor, but there is no copy assignment operator, if you try to use the assignment, You can get a siffault from  

And you do not think you are doing an assignment anywhere, but unless you know all the rules of C ++ (very few new students who do not do the specialist), make sure It is difficult. The easiest way to find out is to declare a private assignment operator and not to define it (or, if you are using C + + 11, declare it deleted) and see if you get a compilation error .

For example:

  straight image {int width_, height_; Int ** image_; Image (integer width, integer height): width_ (width), height_ (height), image_ (0) {image_ = new int * [height_]; For (int i = 0; i! = Height_; ++ i) {image_ [i] = new int [width_]; For (int j = 0; j! = Width_; ++ j) {image_ [i] [j] = 1; }}} Image (Const प्रतिमा and RA): width_ (rhs.width_), height_ (rhs.height_), image_ (0) {image_ = new int * [height_]; For (int i = 0; i! = Height_; ++ i) {image_ [i] = new int [width_]; For (int j = 0; j! = Width_; ++ j) {image_ [i] [j] = rhs.image_ [i] [j]; }}} / * Simulation image to discard & amp; Operator = (Const Image & RA) {If (this == & amp; ra) returns * This; For (int i = 0; i! = Height_; ++ i) {delete [] image_ [i]; } Remove [] image_; Image_ = new int * [height_]; For (int i = 0; i! = Height_; ++ i) {image_ [i] = new int [width_]; For (int j = 0; j! = Width_; ++ j) {image_ [i] [j] = rhs.image_ [i] [j]; }} Return * This; } * / ~ Image () {for (int i = 0; i! = Height_; ++ i) {delete [] image_ [i]; } Remove [] image_; }}; Int main (int, char * []) ​​{image image (200, 300); Image img2 (img); Image img3 (100, 200); IMG3 = IMG2; Return 0; }   

As a comment, if you cancel the copy assignment operator, then the whole thing works.

If this is your problem, then three (,) of the rule.

Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -