PieterP:
There are two possible solutions:
Based on your directives of Post#9, the OP's codes are now compiled without error; however, there are few queries/questions that follow:
struct Point
{
uint8_t X = 0;
uint8_t Y = 0;
Point(uint8_t _x, uint8_t _y): X(_x), Y(_y) {}
Point() = default;
};
struct Rectangle
{
Point LeftBottom;
uint8_t Width;
uint8_t Height;
Rectangle(Point _leftbottom, uint8_t _width, uint8_t _height)
: LeftBottom(2, 3), Width(4), Height(6) {}
};
Point myDimension(12, 3);
void setup()
{
Serial.begin(9600);
Serial.println(myDimension.X); //shows: 12
}
void loop()
{
}
Queries/Questions:
1. I have given values for the arguments/parameters of the initializer list of Rectangle Structure like these:
Rectangle(Point _leftbottom, uint8_t _width, uint8_t _height)
: LeftBottom(2, 3), Width(4), Height(6) {}
(1) How do I create an object using the Rectangle Structure? (something like: Rectangle recta((x,y), u, v)
(2) Once, the object is created; how do I print 2 (the value that has been assigned to X of LeftBottom object which is an instance of Point Structure?
(3) Once, the object is created; how do I print 4 (the value that has been assigned to Width of recta object which is an instance of Rectangle Structure?
2. It looks like that the following two blocks of codes of the Rectangle() constructor are not equivalent. Why not? (Sketch with the top constructor function gets compiled, and the bottom one gives error.)
Rectangle(Point _leftbottom, uint8_t _width, uint8_t _height)
: LeftBottom(_leftbottom), Width(_width), Height(_height) {}
and
Rectangle(Point _leftbottom, uint8_t _width, uint8_t _height)
{
LeftBottom=_leftbottom;
Width=_width;
Height=_height;
}