locked
Interface implementation in WinRT class

    Question

  • In C++/WRL I can declare and implement interface explicitly, like:

    In IDL:

     

        interface IMyInterface : IInspectable
    
        ...
    
    
    

    In C++:

    	class MyComponent :
    
    		public RuntimeClass<IMyInterface>
    
            ....
    
    
    

    How can I do the same for C++/CX? 
    	public ref class WinRTComponent  : IMyInterface??? sealed
            ...
    
    

    Tuesday, December 13, 2011 1:11 PM

Answers

  • It can be sealed.


    Raman Sharma | Program Manager, Visual C++ | @rasharm_msft

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)
    • Marked as answer by Anton K2 Tuesday, December 20, 2011 6:02 AM
    Monday, December 19, 2011 9:43 PM
  • Yes, it works.

    public ref class Foo sealed : IFoo {
    public:
       void bar() { }
       property int p;
    };
    

    • Marked as answer by Anton K2 Tuesday, December 20, 2011 6:02 AM
    Tuesday, December 20, 2011 6:02 AM

All replies

  • You should be able to do something like this:

    public interface class IFoo {
      void bar();
      property int p;
    };
    
    public ref class Foo : IFoo {
    public:
       void bar() { }
       property int p;
    };
    
    

    Thanks,


    Raman Sharma | Program Manager, Visual C++ | @rasharm_msft

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)
    Tuesday, December 13, 2011 8:33 PM
  • Thanks Raman.

    Why Foo class is not sealed in the case?

    Friday, December 16, 2011 11:25 AM
  • It can be sealed.


    Raman Sharma | Program Manager, Visual C++ | @rasharm_msft

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)
    • Marked as answer by Anton K2 Tuesday, December 20, 2011 6:02 AM
    Monday, December 19, 2011 9:43 PM
  • Yes, it works.

    public ref class Foo sealed : IFoo {
    public:
       void bar() { }
       property int p;
    };
    

    • Marked as answer by Anton K2 Tuesday, December 20, 2011 6:02 AM
    Tuesday, December 20, 2011 6:02 AM