Skip to main content
GameDev.net gamedev.net
🔒 Locked

Interfaces

Started by bballmitch Apr 25, 2006 at 8:59 PM 10 replies 1.4k views
Original Post
bballmitch
bballmitch
I know in Java you can do public interface myInterface { . . . } Two questions. Why not just make an abstract class? Is there a such thing in C++?
Mitchen Games
Sneftel
Sneftel
Interfaces define a "can-be-used-as" or "can-be-used-for" relationship; abstract classes define an "is-a" relationship. A class which implements an ICloneable interface, for instance, is asserting that it can be cloned, not that it is fundamentally "a cloneable"; cloneability is among its features but does not define what kind of a thing it is. In contrast, a Circle is-a Shape. We would not normally say that "a circle can be used as a shape". The distinction is fuzzy at times, of course.
bballmitch
bballmitch
Quote:
Original post by Anonymous Poster
Answer two: The way to do this in C++ is to make a base class with (preferably) only abstract methods, and then use multiple inheritance (which does not exist in Java).


But I know there is a keyword in C++ interface . What does that do? I can't figure it out.

Mitchen Games
nsto119
nsto119
Quote:
Original post by bballmitch
Quote:
Original post by Anonymous Poster
Answer two: The way to do this in C++ is to make a base class with (preferably) only abstract methods, and then use multiple inheritance (which does not exist in Java).


But I know there is a keyword in C++ interface . What does that do? I can't figure it out.


There is no interface keyword in C++. There might be in C++/CLI, but not in the "real" C++.

I wish Microsoft wouldn't take the names of popular open standards and try to make them their own.
bballmitch
bballmitch
I have Dev-C++ and when I open a console application and type in interface , it turns blue like a keyword.
Mitchen Games
Saruman
Saruman
Quote:
Original post by nsto119
There is no interface keyword in C++. There might be in C++/CLI, but not in the "real" C++.

Actually you are wrong in thinking that it only exists on the .NET platform as it has been used in Windows C++ apps for a long time.

If you include than you have access to the interface keyword (which I saw used in COM a lot). It is not a standard C++ keyword and is specific to the Windows API. This mysterious 'interface' keyword is just a typedef of struct.

Although I have not checked with versions since 6.0 and it might actually be included as a language feature, as I believe that other environments such as DevCpp also have this.
bballmitch
bballmitch
ah. That explains it. So what does it do?
Mitchen Games
Sneftel
Sneftel
It's not a typedef (you can't typedef keywords), but a #define. In other words, bballmitch: It's not a keyword, it's a macro that Microsoft uses, and which the makers of dev-c++ decided to display as a keyword in their editor.

EDIT: and as for what it does: it just acts like struct. It IS struct.
mreiland
mreiland
As has already been said, interface isn't a keyword in C++. You can use the DevC++ as a frontend for the VC++ toolkits, so perhaps that's why it turns blue.


[edit]

Nevermind, apparently I'm wrong :) I should have waited 2 seconds to post!
Saruman
Saruman
Quote:
Original post by Sneftel
It's not a typedef (you can't typedef keywords), but a #define.

Ah yes my bad sorry, dunno why I put typedef.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.