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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:41:42+00:00 2026-05-23T00:41:42+00:00

Possible Duplicate: Trouble with inheritance of operator= in C++ I updated the code #include

  • 0

Possible Duplicate:
Trouble with inheritance of operator= in C++

I updated the code

#include <QtCore/QCoreApplication>

class Base
{
    int num;
public:
    Base& operator=(int rhs)
    {
        this->num = rhs;
        return *this;
    }
};

class Derive : public Base
{
public:
    int deriveNum;
    using Base::operator =; // unhide the function
};

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    Base base;
    Derive derive1, derive2;

    base = 1;  // calls Base::operator(1) and returns Base&

    derive1 = 11; // calls Base::operator(11) and returns Base&
    derive2 = 22; // calls Base::operator(22) and returns Base&

    derive1 = base;// Which function does it calls??
               // If it calls Base::operator(base) and
                   // returns a Base&, how could it be assigend to derive1?

    return a.exec();
}

I marked the question in the comment, please give me some more help

  • 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-23T00:41:43+00:00Added an answer on May 23, 2026 at 12:41 am

    It is inherited by the derived class. However, the derived class has it own operator = (implictly declared by the compiler), which hides the operator = inherited from the parent class (search and read about “name hiding” in C++).

    If you want the inherited operator = to become visible, you have to explicitly unhide it

    class Derive : public Base
    {
      std::string str;
    
    public:
      using Base::operator =; // unhide
    };
    

    and your code will compile. (If you fix the obvious syntax errors that is. Please, post real code.)

    P.S. This question is asked very often. I provided a link to a more detailed explanation as a comment to your question.

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

Sidebar

Related Questions

Possible Duplicate: Trouble with inheritance of operator= in C++ hello everyone, let's assume I
Possible Duplicate: Pre & post increment operator behavior in C, C++, Java, & C#
Possible Duplicate: what is the difference between const int*, const int * const, int
Possible Duplicate: Android Emulator - Trouble creating user accounts I'm trying to register a
Possible Duplicate: WPF and cross thread operations I am having trouble with a window
Possible Duplicate: When to use static vs instantiated classes I'm having a little trouble
Possible Duplicate: Java GUI repaint() problem? I write a Java code, but I have
Possible Duplicate: select all checkboxes command jquery, javascript I am having trouble selecting all
Possible Duplicate: Sha256 in Objective-C for iPhone Greetings, I'm having terrible trouble generating a
Possible Duplicate: PHP pagination class are there any PHP/Class libraries that i can utilize

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.