'interface' keyword

This is a discussion on 'interface' keyword within the C++ Programming forums, part of the General Programming Boards category; I had never heard of this keyword before, accidently stumbed across it while researching DLL stuff. Is it standard C++? ...

  1. #1
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    'interface' keyword

    I had never heard of this keyword before, accidently stumbed across it while researching DLL stuff. Is it standard C++? Seems like all members are public by default?
    Code:
    interface I
    {
      virtual void M() = 0;
    };
    
    class C : public I
    {
      public:
        virtual void M() {};
    };
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    It is not standard. It is probably a #define for struct.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    If it were a define for struct you'd get warnings inheriting a 'class' from a 'struct'... (have gotten these before ). The keyword appears blue in VC and bold in DevCPP so if not standard it's at least non-official-semi-standard :P

    EDIT: ok, __interface seems like the true keyword, interface is a define for __interface. VC only though...
    http://msdn.microsoft.com/library/de.../key_f-r_3.asp
    Last edited by Magos; 02-21-2006 at 01:41 PM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Call me AirBronto
    Join Date
    Sep 2004
    Location
    Indianapolis, Indiana
    Posts
    195
    dosent DirectX use interfaces?

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Yup, and they use the actual 'interface' keyword too (hidden behind tons of macros).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by Magos
    If it were a define for struct you'd get warnings inheriting a 'class' from a 'struct'... (have gotten these before ). The keyword appears blue in VC and bold in DevCPP so if not standard it's at least non-official-semi-standard :P

    EDIT: ok, __interface seems like the true keyword, interface is a define for __interface. VC only though...
    http://msdn.microsoft.com/library/de.../key_f-r_3.asp
    so this code
    Code:
    #define interface struct
    
    interface base
    {
    	virtual void doStuff(void) = 0;
    };
    
    class derived : public base
    {
    public:
    	virtual void doStuff(void)
    	{
    	}
    };
    won't compile? I'm afraid I call bull......... There are only 2 differences between classes and structs
    1: default access (public in struct, private in class)
    2: you can't forward declare a struct as a class or vice versa
    i.e.
    Code:
    class MyClass;
    
    // some code
    
    struct MyClass // causes a redefinition error
    {
    };
    but you can certainly inherit one from the other.

    as for the interface "keyword", it's an ms-specific extension that's recognised by visual studio. It was originally added in for COM support.
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Line 192 of objbase.h:
    Code:
    #define interface struct

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 09:13 AM
  2. Calling IRichEditOle interface methods
    By Niara in forum C Programming
    Replies: 2
    Last Post: 01-16-2009, 12:23 PM
  3. C++ Interface
    By George2 in forum C++ Programming
    Replies: 8
    Last Post: 01-31-2008, 10:09 PM
  4. OOP in C
    By lyx in forum C Programming
    Replies: 4
    Last Post: 11-23-2003, 12:12 PM
  5. how to search a keyword in C?
    By kreyes in forum C Programming
    Replies: 2
    Last Post: 03-01-2002, 07:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21