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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:27:56+00:00 2026-05-19T06:27:56+00:00

can somebody please explain why can’t I compile this snippet of the code? I

  • 0

can somebody please explain why can’t I compile this snippet of the code? I know that this design is very bad, but I just want to know why I can’t compile it, thanks in advance
P.S. sorry for the format, can’t find backquotes on the panel

//Deriving classes definition 
class IntClass; class DoubleClass;

//The Virtual Number Class. IntClass and FloatClass will derive from this class.

class Number {
    public:
        //return a Number object that's the results of x+this, when x is DoubleClass
        virtual Number& addDouble(DoubleClass& x) = 0;

        //return a Number object that's the results of x+this, when x is IntClass
        virtual Number& addInt(IntClass& x) = 0;

        //return a Number object that's the results of x+this, when x is either
        //IntClass or DoubleClass
        virtual Number& operator+(Number& x) = 0;
};

class IntClass : public Number {
    private:
        int my_number;
    public:
        //Constructor
        IntClass(int n):my_number(n) {}

        //returns the number stored in the object
        int get_number()  {return my_number;}

        //return a DoubleClass object that's the result of x+this
        Number& addDouble(DoubleClass& x){
         return  x.addInt(*this);
        }

        //return an IntClass object that's the result of x+this
        Number& addInt(IntClass& x){
         IntClass* var = new IntClass(my_number + x.get_number());
         return  *var;
        }

        //return a Number object that's the result of x+this.
        //The actual class of the returned object depends on x.
        //If x is IntClass, then the result if IntClass.
        //If x is DoubleClass, then the results is DoubleClass.
        Number& operator+(Number& x){
         return x.addInt(*this);
        }
};

class DoubleClass : public Number {
    private:
        double my_number;
    public:
        //Constructor
        DoubleClass(double n):my_number(n) {}

        //returns the number stored in the object
        double get_number()  {return my_number;}

        //return a DoubleClass object that's the result of x+this
        Number& addDouble(DoubleClass& x){
         DoubleClass* var = new DoubleClass(my_number + x.get_number());
         return *var;
        }

        //return a DoubleClass object that's the result of x+this
        Number& addInt(IntClass& x){
         DoubleClass* var = new DoubleClass(my_number + x.get_number());
         return *var;
        }

        //return a DoubleClass object that's the result of x+this.
        //This should work if x is either IntClass or DoubleClass
        Number& operator+( Number& x){
         return x.addDouble(*this);
        }
};

I have error in the IntClass in addDouble method:

invalid use of undefined type struct DoubleClass

Edited IntClass is not nested class of the NumberClass

  • 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-19T06:27:58+00:00Added an answer on May 19, 2026 at 6:27 am

    Inside IntClass::addDouble, you use the class DoubleClass, but at that point DoubleClass has only a forward declaration, so you can’t call methods on it.

    This can be fixed by putting the body of IntClass::addDouble after the full declaration of class DoubleClass, or by separating your code into header and implementation files.

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

Sidebar

Related Questions

can somebody please explain is it possible to convert this snippet of the code
Can somebody please explain what does this warning mean: undefined reference to 'WinMain@16' ?
Can somebody please explain this IE7 bug to me? It occurs in Standards and
can somebody please explain what this program is doing? .= torg + 1000 main:
can somebody please explain my mistake, I have this class: class Account { private:
Can somebody please explain how this works in jQuery. I tried to find some
I do not know where my head is today, can somebody please explain to
Can somebody please explain with examples (of code) what is the difference between deadlock
I'm getting a force close message here in my code. Can somebody please explain
Can somebody please explain (in succinct terms) what exactly is domain driven design? I

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.