can somebody give me a use for a struct with no member variables.
empty structs
Collapse
X
-
-
Consider a struct as below.
struct Test1 {};
I got from the net that C++ allows empty struct or class (gcc 4.0 supports empty struct even in C). Empty struct/class can be used as a placeholder for future development.
Can somebody illustrate how an empty struct can be used as a placeholder.Comment
-
If you add an empty struct as the first member of another struct, the empty
struct can serve as a "marker interface", i.e. when you cast a pointer to that
outer struct to a pointer of the inner struct and the cast succeeds you know
that the outer struct is "marked" as something. This just works when you use
C++ though; for C there is little use for an empty struct.
kind regards,
JosComment
-
cath8024
Please do not double post on the same subject.
Please do read our posting guidelines.
Banfa
AdministratorComment
Comment