Empty structure in C vs empty structure in C ++

Why is an empty structure in C a violation of the constraint? Why does this rule change in C ++?

Are there any historical reasons?

+7
source share
2 answers

since you do not have inheritance in C, you do not need them. If you just want to have a distinguishable pointer type, you can use pointers for incomplete types.

struct opaque; struct opaque* stranger = 0; 

should work fine.

+8
source

My suggestion:

There are no inheritance, templates, or function overloads in C - there are three main reasons why we use empty structures in C ++ as a base interface, as a template parameter, as a type that helps to overload resolution.

Can you imagine any real use of an empty structure in C?

+3
source

All Articles