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

  • Home
  • SEARCH
  • 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 8391591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:18:17+00:00 2026-06-09T19:18:17+00:00

I have just been learning about operator overloading and I wanted to try to

  • 0

I have just been learning about operator overloading and I wanted to try to make an object that represented a complex number. I wrote the following:

#include <iostream>

using namespace std;

class complexNumber
{
    public:
        double re, im;
        complexNumber(){}
        complexNumber(double a, double b)
        {
            re = a;
            im = b;
        }
        complexNumber operator+ (complexNumber b)
        {
            complexNumber c;
            c.re = re + b.re;
            c.im = im + b.im;
        }
        complexNumber operator- (complexNumber b)
        {
            complexNumber c;
            c.re = re - b.re;
            c.im = im - b.im;
        }
};

int main()
{
    complexNumber a(1,2);
    complexNumber b(4,6);
    complexNumber c;
    complexNumber d;

    c = a + b;
    d = a - b;

    cout << c.re << " + " << c.im << "i" << endl;
    cout << d.re << " + " << d.im << "i" << endl;
}

And I got the result:

2.44156e+253 + 6.95225e-308i

2.44156e+253 + 6.95225e-308i

Any ideas of where I am going wrong here.
Thanks in advance.

  • 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-09T19:18:18+00:00Added an answer on June 9, 2026 at 7:18 pm

    You need to return a value from your functions. Is your compiler not warning you of this?

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

Sidebar

Related Questions

I'm just learning about them, and find it discouraging that they have been deprecated.
I am just learning C# (have been fiddling with it for about 2 days
I'm just beginning to learn Java and I have been very frustrated about learning
I have just been learning about how styles and control templates in WPF can
I have just started learning NHibernate. Over the past few months I have been
I'm learning scheme and until now have been using guile. I'm really just learning
I have just been involved in writing an application that does not use Doctype's
I have been just learning redis and node.js There are two questions I have
I'm 14 and have been learning java for about 4/5 months. I'm coding a
I have been learning ASP.NET MVC for a few months. I have learned about

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.