tags:

views:

49

answers:

2

What is the difference between the following declarations (in C++/CLI):

public interface class IC {};

public interface struct IS {};

Similar situations:

public enum class EC {};

public enum struct ES {};

?

+4  A: 

They are identical.

For details, see MSDN's interface class reference, under Remarks:

interface struct is equivalent to interface class.


I believe Microsoft decided to allow both options just to keep consistency with ref class/ref struct and value class/value struct. However, since interfaces don't have private members, for interface, the two statements become exactly the same.

Reed Copsey
Now when I know that, I think that the redundant construct was introduced because the creators of c++/cli aimed to reduce the number of new keywords. That is why they've come up with solution called context-sensitive keywords. They could't introduce "interface" keyword because it would collide with lots of already written source code (e.g. "interface" type name). So they probably decided to connect it together with class keyword just to make a context, and with struct keyword just to be consistent.
MarcAndreson
A: 

There's no difference. They're equivalent.

Bear in mind than in 'real' C++ there's actually almost no difference between struct and class, other than the default accessibility of members. So in the parallel universe of C++/CLI, where accessibility rules are different anyway, it's not completely mad that they're equivalent.

Will Dean
what do you mean saying "(...) where accessibility rules are different anyway" ? How do they differ ?
MarcAndreson
Well, for a start, you've got more options than in C++, in that you have things like 'public protected' and 'private protected', which are not present in 'normal' C++.
Will Dean