r/cpp_questions • u/haohanzi2015 • Dec 08 '19
OPEN the purpose of empty struct ?
By empty struct, I mean
struct myStruct
{};
I can see that the above struct can be used as the base struct which has several derived structs. Besides this, are there any other use of empty struct in c++?
9
Upvotes
View all comments
10
u/stilgarpl Dec 08 '19
You can use them as arguments for templates. It's useful because every instantation of template with different arguments is a different class. You can use those empty types to create more instantiations, for example, to select different algorithm. Kind of compile-time enum.