Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Deriving a class from more than one interface

Deriving a class from more than one interface

Scheduled Pinned Locked Moved COM
businesshelpquestionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Steve Thresher
    wrote on last edited by
    #1

    How do you derive a class from more than one interface where two or more of the interfaces have methods with the same name, parameters and return type? class CSomeClass : public IInterfaceA, IInterfaceB { public: CSomeClass(); // IUnknown HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID FAR* ppvObj); STDMETHODIMP_(ULONG) AddRef(); STDMETHODIMP_(ULONG) Release(); // IIntefaceA HRESULT STDMETHODCALLTYPE DoStuff(VOID); // InterfaceB HRESULT STDMETHODCALLTYPE DoStuff(VOID); <-- Compiler generates an error }; error C2535: 'HRESULT CSomeClass::DoStuff()' : member function already defined or declared If its as simple as only having one copy of the function then how do you know which interface the function is serving? QueryInterface() handles this by passing in an IID but the functions I'm dealing with have no such parameters. Systems AXIS Ltd - Software for Business ...

    A 1 Reply Last reply
    0
    • S Steve Thresher

      How do you derive a class from more than one interface where two or more of the interfaces have methods with the same name, parameters and return type? class CSomeClass : public IInterfaceA, IInterfaceB { public: CSomeClass(); // IUnknown HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID FAR* ppvObj); STDMETHODIMP_(ULONG) AddRef(); STDMETHODIMP_(ULONG) Release(); // IIntefaceA HRESULT STDMETHODCALLTYPE DoStuff(VOID); // InterfaceB HRESULT STDMETHODCALLTYPE DoStuff(VOID); <-- Compiler generates an error }; error C2535: 'HRESULT CSomeClass::DoStuff()' : member function already defined or declared If its as simple as only having one copy of the function then how do you know which interface the function is serving? QueryInterface() handles this by passing in an IID but the functions I'm dealing with have no such parameters. Systems AXIS Ltd - Software for Business ...

      A Offline
      A Offline
      AndyCheetham
      wrote on last edited by
      #2

      One way around this problem would be to build intermediate C++ classes that derive from a single interface and impliments the clashing method by making a pure virtual call on a nonclashing name. For example: struct IXInterfaceA : public IInterfaceA { //Add new non clashing method as a pure virtual virtual HRESULT STDMETHODCALLTYPE DoStuffOnA(void) = 0; //impliment the clashing method STDMETHODIMP DoStuff(void) { return DoStuffOnA(); } } If you do the same for your other interface IInterfaceB Your CSomeClass would look like this. class CSomeClass : public IXInterfaceA, public IXInterfaceB { public: CSomeClass(); // IUnknown HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, LPVOID FAR* ppvObj); STDMETHODIMP_(ULONG) AddRef(); STDMETHODIMP_(ULONG) Release(); // IIntefaceA HRESULT STDMETHODCALLTYPE DoStuffOnA(VOID); // InterfaceB HRESULT STDMETHODCALLTYPE DoStuffOnB(VOID); }; Hope this help, it helped me. Regards Andy

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups