Firstly, interfaces are not really a native concept for C ++. I am sure that most programmers know what it is, but the compiler does not, and that where you encounter problems. C ++ can do a lot, and I bet you can flip it in the form of many different languages, but if you are going to write C ++, it is best to do something in C ++.
Another thing - there is a lot of gray area. What if you had an “interface” as you expected, but someone did one of them:
I am almost 100% sure that you cannot stop someone from doing this.
You may be able to make sure that there are no member variables, although I'm not sure I agree with this path. Make an empty class, and then do static_assert(sizeof(InterfaceClass) == sizeof(Empty))
. I'm not sure if it can be assumed that the size will be 0 - this is a question for someone more familiar with the standards.
source share