Nested structs...

I defined a new class Rect:
1
2
3
4
5
6
7
8
9
10
struct Rect {
  int x,y;
  int w,h;
  Rect(int x,int y,int w,int h) {
    this->x=x;
    this->y=y;
    this->w=w;
    this->h=h;
  }
};

But I have serious problems when I try to create a struct that contains a Rect variable:
1
2
3
struct Sprite {
  Rect rect;
};

I receive an error message because there isn't a empty constructor in Rect class. What you suggests? I have to use obligatorily dynamic memory? For example:
1
2
3
4
5
6
struct Sprite {
  Rect * rect;
  Sprite() {
    rect=new Rect(1,2,3,4);
  }
};

????? There is a way to do that without using dynamic memory? I think that dynamic memory is superfluous in this specific situation. Or not?
Thanks in advance
Well, i suggest declaring an empty constructor.

I guess you know what that means. If not, read the paragraph about constructers and destructers in this article: http://www.cplusplus.com/doc/tutorial/classes.html

Hope this helps.
Topic archived. No new replies allowed.