In C programming, What does this colon do in struct?
struct ABC:XYZ {int num;}
where XYZ is also a struct. This does not seem to be a bitfield. What does ':' mean here?
In C programming, What does this colon do in struct?
struct ABC:XYZ {int num;}
where XYZ is also a struct. This does not seem to be a bitfield. What does ':' mean here?
The code:
struct ABC:XYZ {int num;}
means "define a struct ABC
which inherits from XYZ
and has a num
member of type int
. Specifically the :
means "inherits from".
That code is equivalent to:
struct ABC : public XYZ {int num;}
For struct
s the default inheritance visibility is public
, for class
es it's private
.
When inherit you usually write:
class Child : public Parent { ... };
you can also write
class Child : Parent { ... };
but for class that would be private inheritance, so you usually see keyword public
there. Same for struct
except if not specified explicitly it would be already public
.