Thread: C++ Interface

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    1,579

    C++ Interface

    Hello everyone,


    Just wondering how COM implementation uses keyword interface without compile error, for a normal C++ project, if we use keyword interface, there will be compile error.

    Code:
    interface IFoo {
    	
    	int func() = 0;
    };
    Compile error:

    --------------------
    1>d:\visual studio 2008\projects\test_virtual1\test_virtual1\main2.cp p(1) : error C2146: syntax error : missing ';' before identifier 'IFoo'
    1>d:\visual studio 2008\projects\test_virtual1\test_virtual1\main2.cp p(1) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    1>d:\visual studio 2008\projects\test_virtual1\test_virtual1\main2.cp p(1) : error C2470: 'IFoo' : looks like a function definition, but there is no parameter list; skipping apparent body
    --------------------

    Any ideas?


    thanks in advance,
    George

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    I don't do .NET, but my beginner's C++ book has 1 age on .NET and says the MS keyword is
    Code:
    __interface
    The error messages appear to me like the interface keyword you are using is not recognized.

    Could it be?

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I don't know anything about COM, but there is no interface keyword in C++. Maybe it's a Microsoft extension or a macro for something like the class keyword?

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi Todd,


    You are doing managed C++? But I am doing non-managed C++.

    Quote Originally Posted by Todd Burch View Post
    I don't do .NET, but my beginner's C++ book has 1 age on .NET
    and says the MS keyword is
    Code:
    __interface
    The error messages appear to me like the interface keyword you are using is not recognized.

    Could it be?

    regards,
    George

  5. #5
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Yes, cpjust!


    Interface is not a part of C++ Spec, I think Visual Studio defines it to struct.

    Quote Originally Posted by cpjust View Post
    I don't know anything about COM, but there is no interface keyword in C++. Maybe it's a Microsoft extension or a macro for something like the class keyword?

    regards,
    George

  6. #6
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    I looked it up on MSDN. Just as I suspected - it requires two underscores in front the keyword:

    http://msdn2.microsoft.com/en-us/lib...tb(VS.71).aspx

    Todd

  7. #7
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    See this too if you want to use the interface keyword without the two underscores:

    http://msdn2.microsoft.com/en-us/library/ms858713.aspx

  8. #8
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Chappell Hill, Texas
    Posts
    2,332
    Quote Originally Posted by George2 View Post
    You are doing managed C++?
    Nope. Not me.

  9. #9
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks for your great links!


    My question is answered.

    Quote Originally Posted by Todd Burch View Post
    Nope. Not me.

    regards,
    George

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, 10:13 AM
  2. Calling IRichEditOle interface methods
    By Niara in forum C Programming
    Replies: 2
    Last Post: 01-16-2009, 01:23 PM
  3. Cannot get interface flags: Invalid argument
    By nasim751 in forum C Programming
    Replies: 3
    Last Post: 04-14-2008, 02:29 AM
  4. marshall interface needed?
    By George2 in forum Windows Programming
    Replies: 2
    Last Post: 04-06-2008, 07:15 PM
  5. OOP in C
    By lyx in forum C Programming
    Replies: 4
    Last Post: 11-23-2003, 01:12 PM