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

  • SEARCH
  • Home
  • 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 6319811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:52:03+00:00 2026-05-24T15:52:03+00:00

Ive got a diamond. I want to access class member. I am using mingw.

  • 0

Ive got a diamond. I want to access class member. I am using mingw.
Question is: How to access member “top::A” without redeclaring classes

#include <cstdio>
class top {
public:
    const char A;
    top(): A('t') {}
};
class left: public top {
public:
    const char A;
    left():A('l'){}
};
class right: public top {};
class bottom: public left, public right {};

int main() {
    bottom obj;
    printf("%c\n", obj.bottom::right::A); //using right::A, inherited from top::A
    printf("%c\n", obj.bottom::left::A); //using left::A and left::top::A is hidden
    //printf("%c\n", obj.bottom::left::top::A); //error. How to access it?
    return 0;
}

When I remove comment mingw gives me an error:

'top' is an ambiguous base of 'bottom'  

Update: Looks like casting types works:

printf("%c\n", static_cast<top>(static_cast<left>(obj)).A);
printf("%c\n", static_cast<left>(obj).::top::A);
printf("%c\n", reinterpret_cast<top&>(obj).A);//considered bad
printf("%c\n", (reinterpret_cast<top*>(&obj))->A);//considered evil
//      printf("%c\n", static_cast<top&>(obj).A);//error
  • 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-24T15:52:03+00:00Added an answer on May 24, 2026 at 3:52 pm

    Without going for virtual inheritance, you can massage the type a bit to convince the compiler to pick the correct base class:

    printf("%c\n", static_cast<left&>(obj).::top::A);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive got a question to Spring Security 3.0.5. When using Spring Security to secure
Ive got a problem that if I have a template class, which in turn
Ive got an assignment to create an image gallery using flickr - this has
Ive got the following question and im trying to figure out the answer: You
Ive got a strange task. Specifically i want to check for insane media file
If I've got three classes like this: class BaseClass(object): def __init__(self, base_arg, base_arg2=None): ...
Ive got a button in a UICell. I want a list(a table view like
Ive got this following code in VB, want to use it into c# and
Ive got the following code which I hacked together from website examples. It works
Ive got a view helper in library/my/view/helper/gravatar and so in any view I can

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.