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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:21:44+00:00 2026-05-19T09:21:44+00:00

My files: cpu_add.h #ifndef CPU_ADD_H #define CPU_ADD_H double add_double_double(double a, double b) {return (a+b);}

  • 0

My files:

cpu_add.h

#ifndef CPU_ADD_H
#define CPU_ADD_H

double add_double_double(double a, double b) {return (a+b);}
double add_int_double(int a, double b) {return ((double)(a)+b);}
int   add_int_int(int a, int b) {return (a+b);}

#endif

I am allowed only to use the functions above. Can’t use the operator ‘+’ in my own code.

poly_subtype.h

#ifndef POLY_SUBTYPE_H
#define POLY_SUBTYPE_H
#include <iostream>
#include "q3.h"
#include "cpu_add.h"
using std::cout;
using std::endl;

//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;

        //Print the number stored in the object
        virtual void print_number() = 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;}

        //print the number stored in the object
        void print_number() {cout << my_number << endl;}

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

        //return an IntClass object that's the result of x+this
        Number& addInt(IntClass& x);

        //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);
};

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;}

        //Print the number stored in the object
        void print_number() {cout << my_number << endl;}

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

        //return a DoubleClass object that's the result of x+this
        Number& addInt(IntClass& x);

        //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);
};

#endif

I need to implement the next functions:

Number& IntClass::addInt(IntClass& x);
Number& IntClass::addDouble(DoubleClass& x);
Number& IntClass::operator+(Number& x);
Number& DoubleClass::addInt(IntClass& x);
Number& DoubleClass::addDouble(DoubleClass& x);
Number& DoubleClass::operator+(Number& x);

So for example in my the q3.h I wrote:

#ifndef Q3_H_
#define Q3_H_

#include "cpu_add.h"
#include "poly_subtype.h"

Number& IntClass::addInt(IntClass& x){
    IntClass num(add_int_int(my_number, x.get_number()));
    return num;
}
#endif /* Q3_H_ */

and I get the next error:

expected constructor, destructor, or type conversion before '&' token   q3.h    ‪/pl5‬  line 48 C/C++ Problem

What does it mean?

Thanks.

  • 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-19T09:21:45+00:00Added an answer on May 19, 2026 at 9:21 am

    This is caused because you put all your code in headers (maybe thinking the Java way?).

    When you include poly_subtype.h it includes q3.h which then includes poly_subtype.h in an attempt to define various classes. Due to your include guards the second include has no effect. Then when the compiler attempts to compile q3.h it has no idea what the Number class is, and generates that error.

    The fix to this is to put your method implementations into source files that are only compiled once. It will prevent the nested inclusion problems. Alternately I can’t see why poly_subtype.h needs to include q3.h at all. If you remove that include it might fix it.

    Also as a side note, IntClass::addInt returns a local by reference which is definitely incorrect although it may appear to work. You should instead return *this; which is the actual object being modified (I believe – it’s hard to tell from your small sample).

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

Sidebar

Related Questions

Files: Website\Controls\map.ascx Website\App_Code\map.cs I'd like to create a strongly typed instance of map.ascx in
Some files in our repository are individual to each developer. For example some developers
Flat files and relational databases give us a mechanism to serialize structured data. XML
string [] files = new string[2]; files[0] = ThinkFarAhead.Example.Settings.Configuration_Local.xml; files[1] = ThinkFarAhead.Example.Settings.Configuration_Global.xml; //Resharper complains
pdb files contain symbol information for .NET assemblies. I'd like to read a pdb
all files in ~/Cipher/nsdl/crypto can be found here java files compiled with gcj, see
The files residing in .settings in a Dynamic Web Project are: .settings/ |-- org.eclipse.jdt.core.prefs
CSS and Javascript files don't change very often, so I want them to be
If I open files I created in Windows, the lines all end with ^M
How do I ignore files in Subversion? Also, how do I find files which

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.