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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:12:44+00:00 2026-05-18T07:12:44+00:00

I am currently writing a program that models various types of numbers and manages

  • 0

I am currently writing a program that models various types of numbers and manages them polymorphically in a Set object (already written and tested). My inheritance relationship is this:
Multinumber (all virtual functions, virtual class)
inherited by Pairs, Complex, Rational
The subclasses all have mostly the same functions with different parameters.

The problem that I am running into is in functions like this:

Multinumber& Complex::operator=(const Multinumber &rhs)
{
   imag=rhs.imag;
   real=rhs.real;
   return *this;
}

Because I am treating this polymorphically, my return types and parameters all have to be of type Multinumber, in order to override the base class’s parameters. However, I am having a terrible time getting this to compile. I am getting a boatload of errors along the lines of:

error: 'const class Multinumber' has no member named 'imag'

which is true. Multinumber does not have an imag attribute or function. But how can I get the compiler to realize that the Multinumber& rhs will always be Complex, or to treat it as such? Thank you for your help.

This is what my superclass looks like:

class Multinumber
{
public:
virtual Multinumber& operator+(Multinumber&);
virtual Multinumber& operator=(Multinumber&);
virtual bool operator==(Multinumber&);
virtual string object2string();
virtual Multinumber& makeobject(double, double)=0;
};
  • 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-18T07:12:45+00:00Added an answer on May 18, 2026 at 7:12 am

    I think you’ll have to cast. Try this:

    Multinumber& Complex::operator=(const Multinumber &rhs){
        const Complex & _rhs = dynamic_cast<const Complex &>(rhs);
        imag=_rhs.imag;
        real=_rhs.real;
        return *this;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently writing a program that takes other programs, copies them, and stores
I'm currently writing a java program that requires some Data to run. The data
I am writing a program that generates excel reports, currently using the Microsoft.Interop.Excel reference.
I'm currently writing a program that needs to compare each file in an ArrayList
Backgorund I am currently writing a program that allows a user to select a
I'm writing a Linux program that currently compiles and works fine on x86 and
I am currently writing a program that will read part of the windows system
I'm currently writing a program that uses ; as a seperator and extracts the
Hey guys, Im working with wpf 3d, im currently writing a program that will
I'm currently writing a Perl program that is to read a given file (either

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.