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 366471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:38:10+00:00 2026-05-12T13:38:10+00:00

In working on Kira3, I was playing around with the C++ compiler and looking

  • 0

In working on Kira3, I was playing around with the C++ compiler and looking for a good way of implement Kira’s duck typing. I was hoping (as it has been a few years of direct C++ programming) that I could use multiple inheritance for member access under multiple types. Alas, I have failed so far…

The ideal code would look like:

class WithX { public: int x; };
class WithY { public: int y; };
class WithZ { public: int z; };

class Point2D : public WithX, public WithY { };
class Point3D : public WithZ, public WithX, public WithY { };

void ZeroOut(Point2D * p) { p->x = 0; p->y = 0; };

int _tmain(int argc, _TCHAR* argv[])
{
    Point3D* p = new Point3D();
    p->x = 1;
    p->y = 1;
    p->z = 1;
    ZeroOut(p);
    return 0;
}

However, it throws a typing error at the invocation of ZeroOut(p). This is ultra sad face. I can force it work by creating a type tower. In the above example, I could change
class Point3D : public WithZ, public WithX, public WithY { };
to
class Point3D : public Point2D, public WithZ { };

The problem now is when I have structures that overlap. I would either throw an error that would be a pain to solve in kira code, or I have the compiler do something different. I tried

class Point3D : public Point2D, public WithZ, public WithX, public WithY { }; 

with the hope of the compiler combining them, but this gives ambiguous access to member variables. This can be fixed by replicating writes to the ambiguous member variables, and this could be a solution during my compilation phase. This solution requires more memory.

Any ideas how to solve this without a memory loss?

Or, is there a way to cast variables to multiple types? like

(WithX,WithY *)p
  • 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-12T13:38:10+00:00Added an answer on May 12, 2026 at 1:38 pm

    I tried … with the hope of the compiler combining them, but this gives ambiguous access to member variables.

    To solve that problem, try virtual inheritance.

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

Sidebar

Related Questions

Working with JSF 2.0 (and Primefaces), is there a way to fire an ActionListener
working on using a formula ive been using for a while to find distances
Working on a project at the moment and we have to implement soft deletion
Working with TCL and I'd like to implement something like the Strategy Pattern .
Working on a small game using an HTML5 canvas, and javascript. And it's working
Working with an undisclosed API, I found a function that can set the number
Working with Reporting Services 2008 r2. So here's my issue: We have 5 reports
Working with H2 I get this error when I try to write a row
Working on the problems on Project Euler to try to learn Clojure. I'm on
Working with MS Access for the first time and coming across a few problems

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.