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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:36:15+00:00 2026-06-01T01:36:15+00:00

For example, I have some class hierarchy (possibly, with all kinds of inheritance –

  • 0

For example, I have some class hierarchy (possibly, with all kinds of inheritance – public, private, public virtual, multi-inheritance, etc.):

class A {
  int a;
public:
  virtual ~A() {}
};

class B: public A { int b; };
class C: public virtual B { int c; };
class E: public virtual B { int e; };
class F: public C, public E { int f; };

Using casts I get pointers to every sub-object of the main “big” object:

F * f = new F;
E * e = f;
C * c = f;
B * b = f;
A * a = f;

What pairs of these pointers may I compare for equality (operator==) and why?
Will the comparison use delta-logic or some other technique?

What are the possible situations, when I can’t compare pointers to the same complex object?
What kind of object it can be?

I expect, that all of the pointers to the same object are always equal.

  • 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-06-01T01:36:17+00:00Added an answer on June 1, 2026 at 1:36 am

    You can compare two pointers if one pointer type is implicitly convertible to the other; that is, if they both point to the same type, or one points to a base class of the other’s. The conversion will make the necessary adjustment to the address so that, if both pointers point to the same object, they will compare equal.

    In this case, you can compare any pair except c == e, since neither of C nor E is derived from the other. To compare those, you would either need to cross-cast, or to convert both to their common base class; neither of these can be done implicitly.

    By the way, there’s no need for dynamic_cast in your code, since you’re casting to base class pointers and that safe conversion can be done implicitly.

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

Sidebar

Related Questions

I have some example target = $this.attr('data-target') || e.preventDefault() || (href = $this.attr('href')) &&
Has anyone done this / have some example code?
I have some .net apps running that I need to monitor for example, then
I have some simple shell scripting tasks that I want to do For example:
I have some URLs, like http://www.example.com/something?param1=value1&param2=value2&param3=value3 and I would like to extract the parameters
I have some null struct, for example: struct null_type { null_type& someNonVirtualMethod() { return
I have some String[] arrays, for example: ['a1', 'a2'] ['b1', 'b2', 'b3', 'b4'] ['c1']
I have some data with messed-up accented characters. For example in the data we
I have some tables that benefit from many-to-many tables. For example the team table.
In C++, assume following class hierarchy: class BaseClass { }; class ChildClass : public

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.