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. C / C++ / MFC
  4. error 2039 {dtor} is not element of ImyInterface - when does this happen?

error 2039 {dtor} is not element of ImyInterface - when does this happen?

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
2 Posts 1 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.
  • F Offline
    F Offline
    FriendOfAsherah
    wrote on last edited by
    #1

    I have declared a simpl interface using

    __interface ImyInterface
    {
    virtual Method1() abstract;
    virtual Method2() abstract;
    };
    class MyClass : public ImyInterface, public CBase
    {
    public:
    MyClass();
    virtual ~MyClass();
    virtual Method1();
    virtual Method2();

    protected:
    int member1, member2;
    };

    This is implemented in big code where I use downcasts like

    CBase* ptr = new CMyClass();
    dynamic_cast(ptr);

    and some other typecasting of ImyInterface* found only by "search complete project" on one hand destructors are not allowed in an Interface because __interface uses __declspec(novtable) on the other hand the compiler wants to have a destructor (error is shown at "}" of the derived class) What constructs in the code will force the compile to raise this error, and, is the usage of __interface in c++ too special for interfaces and I should use struct only?. In common: when never use interface as a base of a class?

    F 1 Reply Last reply
    0
    • F FriendOfAsherah

      I have declared a simpl interface using

      __interface ImyInterface
      {
      virtual Method1() abstract;
      virtual Method2() abstract;
      };
      class MyClass : public ImyInterface, public CBase
      {
      public:
      MyClass();
      virtual ~MyClass();
      virtual Method1();
      virtual Method2();

      protected:
      int member1, member2;
      };

      This is implemented in big code where I use downcasts like

      CBase* ptr = new CMyClass();
      dynamic_cast(ptr);

      and some other typecasting of ImyInterface* found only by "search complete project" on one hand destructors are not allowed in an Interface because __interface uses __declspec(novtable) on the other hand the compiler wants to have a destructor (error is shown at "}" of the derived class) What constructs in the code will force the compile to raise this error, and, is the usage of __interface in c++ too special for interfaces and I should use struct only?. In common: when never use interface as a base of a class?

      F Offline
      F Offline
      FriendOfAsherah
      wrote on last edited by
      #2

      found out the bugmyself now I used the virtual keyword in the declaration

      class MyClass : virtual public ImyInterface, public CBase

      removing the virtual keyword makes the error disappear :)

      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