You seem to be a little confused by “static structures” because in C ++ there are no such things as static structures (unlike languages like C #, where static classes are a workaround for there being no global functions).
What you do is instantiate this class and create a static (and constant) instance ( margin ). So your structure is not static, you just define the structure and create an instance of static const belonging to MyWidget . Now the difference between the two examples should be obvious.
In the first example, you create a static variable called margin that belongs to MyWidget , which means you can access the horizontal element this way
MyWidget::margin.horizontal
Where margin is the instance you created.
If you created static structure members, you cannot do this. Instead, you will have to access them as follows:
MyWidget::Margin::horizontal
Where margin is a struct . Note, however, that in the second case, there is no need for a static margin instance, since it does not have instance fields associated with it.
source share