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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:52:02+00:00 2026-06-07T20:52:02+00:00

If there is a class class complex { private: float real,imag; public: complex operator

  • 0

If there is a class

class complex
   {
     private:
        float real,imag;
     public:
       complex operator +(complex c)
       {
         complex t;
         t.real=real+c.real;
         t.imag=imag+c.imag;
         return t;
       }

and in main if we call overloaded operator by

c3=c1+c2;

then compiler internall converts as c3=c1.operator+(c2)

similarly in similar example of operator overloading,chaining of =

class circle
  {
    private:
      int radius;
      float x,y;
    public:
      circle()
      {}
      circle(int rr,float xx,float yy)
      {
        radius=rr;
        x=xx;
        y=yy;
      }
      circle& operator=(const circle& c)
        {
          cout<<endl<<"assignment operator invoked";  
          radius=c.radius;
          x=c.x;
          y=c.y;
          return *this;
        }
int main()
{
    circle c1 (10,2.5,2.5);
    circle c2,c3;
    c3=c2=c1;
    c1.showdata();
    c2.showdata();
    c3.showdata();
    return 0;
} 

Overloaded = to operator will be called 2 times first for c2=c1 and then for c3=c2.
then how will compiler treat c2=c1 with its function prototype??how will compiler internally convert this overloaded operator = call??(plz tell in reference with above addition example)
Whose private fields will b accessed and to ahich object value will be returned??

  • 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-07T20:52:04+00:00Added an answer on June 7, 2026 at 8:52 pm
    c3=c2=c1;
    

    is similarly evaluated as

    c3.operator=(c2.operator=(c1))
    

    c2.operator=(c1) returns a reference to c2 after it was assigned c1.

    Note that for your class, you don’t need to overload operator = since the compiler-generated one does the exact same thing.

    And if you do, you should obey the rule of three – and also add a destructor and copy constructor. But, again, your class doesn’t require either.

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

Sidebar

Related Questions

Is there a class that overwrites the .MainMenu_MenuItem class for the Main Menu? I
I've got a class with one public method and many private methods which are
I've got the following simple code: package main; import java.util.concurrent.*; public class Main {
There is some class wComplex with == operator. #ifndef WCOMPLEX_H #define WCOMPLEX_H #include <stdio.h>
In my library there's a class like this: class Foo { public: void doSomething();
Consider the following class: public class MyIntSet { private List<int> _list = new List<int>();
There is class Road with its Road.h and Road.cpp which contains implementation of method
Say there is: class A(B): ... where B could be object and ... is
Is there a class in the ASP.NET MVC framework that represents a controller name
Is there a __CLASS__ macro in C++ which gives the class name similar to

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.