Inherit Interface Implementation

Basti Funck

I'm new to C++ but have some programming experience in high-level languages (Java, etc.). The main problem I'm currently facing is to understand inheritance and interfaces in C++.

testsurface.h

#include <QSurface>

class TestSurface : public virtual QSurface
{
public:
    TestSurface(SurfaceClass clazz) : QSurface(clazz) { }
    ~TestSurface() { }

    virtual QSurfaceFormat      format()        = 0;
    virtual QSize               size()          = 0;
    virtual QPlatformSurface*   surfaceHandle() = 0;
    virtual SurfaceType         surfaceType()   = 0;
};

testwindow.h

#include <QWindow>
#include "testsurface.h"

class TestWindow : public QWindow, public TestSurface
{
public:
    TestWindow() : QWindow(), TestSurface(QWindow::Window) { }
    ~TestWindow() { }
};

In my understanding, TestSurface passes all abstract methods from QSurface along. Because of TestWindow is inheriting QWindow which is inheriting QSurface I would expect that all needed methods of TestSurface::QSurface are implemented through TestWindow::QWindow but this isn't the case because I get following error messages upon building:

C2512: C:\...\Qt\Projects\Test2\testwindow.h:10: Erroe: C2512: 'QSurface::QSurface': no appropriate default constructor available

and

C:\...\Qt\Projects\Test2\main.cpp:12: Error: C2259: 'TestWindow': Instance of abstract class can't be created because of following members:
"QSurfaceFormat TestSurface::format(void)": is abstract
    c:\...\qt\projects\test2\testsurface.h(12): See declaration of 'TestSurface::format'
"QSize TestSurface::size(void)": is abstract
    c:\...\qt\projects\test2\testsurface.h(13): See declaration of 'TestSurface::size'
"QPlatformSurface *TestSurface::surfaceHandle(void)": is abstract
    c:\...\qt\projects\test2\testsurface.h(14): See declaration of 'TestSurface::surfaceHandle'
"QSurface::SurfaceType TestSurface::surfaceType(void)": is abstract
    c:\...\qt\projects\test2\testsurface.h(15): See declaration of 'TestSurface::surfaceType'
"QSurfaceFormat QSurface::format(void) const": is abstract
    D:\...\msvc2013_64_opengl\include\QtGui/qsurface.h(67): See declaration of 'QSurface::format'
"QPlatformSurface *QSurface::surfaceHandle(void) const": is abstract
    D:\...\msvc2013_64_opengl\include\QtGui/qsurface.h(68): See declaration of 'QSurface::surfaceHandle'
"QSurface::SurfaceType QSurface::surfaceType(void) const": is abstract
    D:\...\msvc2013_64_opengl\include\QtGui/qsurface.h(70): See declaration of 'QSurface::surfaceType'
"QSize QSurface::size(void) const": is abstract
     D:\...\msvc2013_64_opengl\include\QtGui/qsurface.h(73): See declaration of 'QSurface::size'
dtech

That won't work, QWindow is not using virtual inheritance when inheriting QSurface.

class Q_GUI_EXPORT QWindow : public QObject, public QSurface {...};

If you want multiple interfaces to "join a base interface", they all must use virtual inheritance.

           Base
            / \
           /   \
  virtual /     \ virtual
     Der1         Der2
          \     /
           \   /
            \ /
           Join

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

F# Interface Implementation

From Dev

Using interface to differentiate implementation

From Dev

Implementing Interfaces That "Inherit" (Implement) A Common Interface?

From Dev

Deserialising an implementation of an interface

From Dev

Why interface cannot inherit pure abstract class

From Dev

Implementation of Queue<E> interface

From Dev

Separating the Interface and Implementation in C

From Dev

Get names of structs that implement an interface or inherit a struct

From Dev

How to inject an interface implementation?

From Dev

Interface/Implementation in ANSI C

From Dev

F# inherit interface

From Dev

Interface implementation with optional arguments

From Dev

Implementation of an Interface with an "anonymous" method

From Dev

Singleton and Interface implementation

From Dev

Generic Interface missing implementation

From Dev

Anonymous interface implementation in Golang

From Dev

force explicit interface implementation

From Dev

Interface inherit from other interface in golang

From Dev

Is it possible to inherit the implementation of an interface

From Dev

Is there a way to extend a built-in type to inherit an interface?

From Dev

Inherit custom TabBar and implementation of resizeEvent

From Dev

Partially inherit an interface in Java?

From Dev

Can a C++ interface inherit from a class with full implementation?

From Dev

Why can not inherit from Interface

From Dev

Can a class inherit implementation of a method contruct imposed by an interface from other class?

From Dev

Is it possible to inherit the default IShellFolder implementation?

From Dev

F# inherit interface

From Dev

Inherit from two hierarchical interface?

From Dev

How can my class inherit an interface and QObject ?

Related Related

  1. 1

    F# Interface Implementation

  2. 2

    Using interface to differentiate implementation

  3. 3

    Implementing Interfaces That "Inherit" (Implement) A Common Interface?

  4. 4

    Deserialising an implementation of an interface

  5. 5

    Why interface cannot inherit pure abstract class

  6. 6

    Implementation of Queue<E> interface

  7. 7

    Separating the Interface and Implementation in C

  8. 8

    Get names of structs that implement an interface or inherit a struct

  9. 9

    How to inject an interface implementation?

  10. 10

    Interface/Implementation in ANSI C

  11. 11

    F# inherit interface

  12. 12

    Interface implementation with optional arguments

  13. 13

    Implementation of an Interface with an "anonymous" method

  14. 14

    Singleton and Interface implementation

  15. 15

    Generic Interface missing implementation

  16. 16

    Anonymous interface implementation in Golang

  17. 17

    force explicit interface implementation

  18. 18

    Interface inherit from other interface in golang

  19. 19

    Is it possible to inherit the implementation of an interface

  20. 20

    Is there a way to extend a built-in type to inherit an interface?

  21. 21

    Inherit custom TabBar and implementation of resizeEvent

  22. 22

    Partially inherit an interface in Java?

  23. 23

    Can a C++ interface inherit from a class with full implementation?

  24. 24

    Why can not inherit from Interface

  25. 25

    Can a class inherit implementation of a method contruct imposed by an interface from other class?

  26. 26

    Is it possible to inherit the default IShellFolder implementation?

  27. 27

    F# inherit interface

  28. 28

    Inherit from two hierarchical interface?

  29. 29

    How can my class inherit an interface and QObject ?

HotTag

Archive