Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5947363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:57:12+00:00 2026-05-22T16:57:12+00:00

I need a layer of abstraction involving QWidget that can be QGLWidget , and

  • 0

I need a layer of abstraction involving QWidget that can be QGLWidget, and I wonder if there is a way to say to the compiler, “Any time you have a doubt (ambiguities) try to use the default base I give you”, of course if there is ambiguities it can’t resolve with the default choice it prompts errors just like it does. My aim is not have to explicitly solve each of ambiguities one by one since I will always re-direct them to the same class.

Quick setup,

#Qt inheritance (very roughly...)
class QWidget {}; 
class QGLWidget : public QWidget {}; 

#my side
class MyAbstract : public QWidget {}; //used by a factory
class MyClass1 : public MyAbstract {}; 
class MyClass2 : public MyAbstract, public QGLWidget{};

I’am aware compiler can’t determine by its-self witch duplicated methods to use for the MyClass2 class, since QGLwidget inherits and re-implement most of the QWidget, but can I tell to the complier to use QGLWidget first since I know that’s what I want ?

Qt is just an example here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:57:13+00:00Added an answer on May 22, 2026 at 4:57 pm

    I personally doubt that this kind of automatic disambiguation is feasible in C++ at the language level.

    What is possible is, case-by-case, disambiguate by explicitly giving the class whose method should be executed, like this:

    QGLWidget::ambiguous_method(...
    

    This is not what you are asking for, I know, and I am sure you already know about it. I am saying just for completeness.

    On another hand, I am not sure that this kind of automatic disambiguation would be desirable or simply helpful, because the main point about multiple inheritance being “delicate” is the replication of data inside of the derived class. If you had automatic disambiguation, you would end up using sometimes (when there is no ambiguity) the partial object corresponding to a base class, and in other cases the partial object corresponding to the other base class (because of automatic disambiguation) and you would get a mosaic of things that would not make any sense, i.e. a corrupt object…

    Finally, I think that this kind of automatic disambiguation would be infeasible in case you have more complex inheritance diagrams, like, following your example:

    class Nasty : QGLWidget {};
    
    class Very_nasty : Nasty, MyClass2 {};
    

    There would be no possibility of automatic disambiguation. Indeed, say that the classes you provided form a library and that you decided, when building the library, to use MyClass2::QGLWidget as a base for disambiguation.

    Now, I take your library and define two more classes like the ones I gave. Very_nasty inherits QGLWidget from Nasty and from Class2; each one has got a QGWidget inside, and overall I have 3 of them (because Class2 already inherited it twice).

    Now suppose that for me, a base class for disambiguation should be Very_Nasty::Nasty::QGLWidget, given the semantics of my class. If you say that automatic disambiguation is a way to resolve ambiguities with multiple inheritance, I should be able to specify it with each case of multiple inheritance.

    What would happen if I call through Very_nasty a method inherited from MyClass2?

    What would happen if I call through Very_nasty a method inherited from Nasty?

    They would take two different disambiguation paths. Clash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it even possible to create an abstraction layer that can accommodate relational and
I need to make a div layer so that when you click on it
What I need is a way to modify a vector layer representation without downloading
I need a custom layer (extended by new variable and a method) and did
Within my logic layer I have the need to check permissions for a wide
I am working on a prototype project and need to put a new layer
I have an Android MapView in which i need to have a second layer
I have the standard repository pattern with a service layer and I need to
I need a way to programaticaly block and then later unblock specific websites based
I wonder if you can help me. I'm writing a game (2d) which allows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.