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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:55:00+00:00 2026-06-17T22:55:00+00:00

The following question might look like a duplicate but I couldn’t find the exact

  • 0

The following question might look like a duplicate but I couldn’t find the exact idea anywhere else in the site.

A brief introduction: This question raised as I was trying to understand a little more complexity inheritance combination in my class.

One note before I present the question – I don’t look for a sort of “Solution”, only wish to discuss with you about the topic and acquire a better thinking.

Suppose you have the following lines:

class C : public B 
{
    public : 
        C (const B& b) : B (b) {}
        B& operator*() {return *this;}
};

int main() {
    A* pA = new B();
    C& c = pA -> doIt();
    *c = *pA;
    c = *pA;
    return 1;
}

This code isn’t full and this is the whole purpose – assume it does complie and extract the constraints in this code.
Still I wouldn’t just write a code and ask you to explain any constraint of the top off your head but instead I will add my concreate question:

What constraints do we have for the following line :

C& c = pA -> doIt();

As far as I understand, the above code has one staring constraint which is the hierarchy order of these class : C is derived of B and B is dervied of A (correct me If I’m wrong..)

I was trying to actually define these classes while keeping the hierarchy I described above, and I couldn’t have doIt() to return a type of its derived class C. I can use incomplete type C& in the prototype of an A function but yet I cannot return an object of type C.

Thank you in advance,
SyndicatorBBB

  • 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-17T22:55:01+00:00Added an answer on June 17, 2026 at 10:55 pm

    Try this:

    class C;
    
    struct A
    {
        C & doIt();
    };
    
    struct B : A
    {
      void operator=(A const &) { }
    };
    
    class C : public B
    {
    public :
        using B::operator=;
        C (const B & b) : B(b) {}
        B & operator*() { return *this; }
    };
    
    C & A::doIt()
    {
        static B bimpl;
        static C cimpl(bimpl);
        return cimpl;
    }
    

    Note that the implicit assignment operator hides the base version, so we need explicit unhiding of the operator with the using declaration.

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

Sidebar

Related Questions

First, my question might sound like a duplicate, but I have been going through
I might have pretty basic question about regex. I have the following regex, which
might be a silly question nonetheless: I'm playing around with the following code: $a='a';
The following question is not a typical programming question, but IMHO programmers are affected
I have the following SQL design issue. The code below might look a little
I'm trying to sort an array of version numbers that might look like this
Apologies if the question has already been answered elsewhere but I look around already
This might be the least important Scala question ever, but it's bothering me. How
I've just started programming with Java, so might appear as silly question, but I
The following question was asked in one of my interview (few years back) What

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.