0

What is the best and shortest way to code these classes without compiler error

"field 'image' has incomplete type Image image;"

struct ImageFrame {
   Image image;
};
struct Image {
   ImageFrame imageFrame;
};

I have tried putting

struct ImageFrame;
struct Image;

before, but error still occurs, even if the order of anything is changed.

EDIT: Using reference it works like this:

struct ImageFrame;
struct Image;

struct ImageFrame {
    Image* image;
};
struct Image {
    ImageFrame imageFrame;
};

Are there any memory issues at "Image* image" I should take care of? (memory leaks if *image not deleted)

marirena
  • 300
  • 2
  • 10
  • 1
    Use references or pointers in the declaration of the member variables. – πάντα ῥεῖ May 22 '16 at 12:44
  • 2
    What you are trying to do is impossible. A class cannot contain itself. If you ever manage to do this, our universe will immediately disappear into a massive black hole. – Sam Varshavchik May 22 '16 at 12:49
  • _"Are there any memory issues at "Image* image" I should take care of?"_ Not more than already are considered [here](http://stackoverflow.com/questions/4172722/what-is-the-rule-of-three) – πάντα ῥεῖ May 22 '16 at 13:09

0 Answers0