locked
C3766 when deriving a class and interface

    Question

  • Hi,

    I have a Windows Runtime Component C++/CX project and while trying to compile this piece of code:

        public interface class IAaa
        {
            void MethodA ();
        };
    
        public interface class IBbb : IAaa
        {
            void MethodB ();
        };
    
        ref class Aaa : IAaa
        {
        public:
            virtual void MethodA () { }
        };
    
        ref class Bbb : public Aaa, IBbb
        {
        public:
            virtual void MethodB () { }
        };

    I get this error message:

    error C3766: Bbb must provide an implementation for the interface method 'void IAaa::MethodA(void)'

    The same code compiles just fine in C#. Is there something wrong with the code of could this be a compiler bug?

    Thanks

    Wednesday, November 28, 2012 2:44 PM

Answers

  • Well, the document says:

    If interface B inherits from interface A, and ref class C inherits from B, C must implement both A and B. 

    And this is clear. However in my case class Aaa already implements MethodA and class Bbb inherits it. Currently I have this workaround:

        ref class Bbb : public Aaa, IBbb
        {
        public:
            virtual void MethodA () override { Aaa::MethodA (); }
            virtual void MethodB () { }
        };



    Thursday, November 29, 2012 7:43 AM

All replies

  • Hi,

    Based on this document, class Bbb must implement MethodB and MethodA.

    Please check the Interface Inheritance hierarchies section
    http://msdn.microsoft.com/en-us/library/windows/apps/hh755792.aspx

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, November 29, 2012 6:26 AM
  • Well, the document says:

    If interface B inherits from interface A, and ref class C inherits from B, C must implement both A and B. 

    And this is clear. However in my case class Aaa already implements MethodA and class Bbb inherits it. Currently I have this workaround:

        ref class Bbb : public Aaa, IBbb
        {
        public:
            virtual void MethodA () override { Aaa::MethodA (); }
            virtual void MethodB () { }
        };



    Thursday, November 29, 2012 7:43 AM