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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:55:18+00:00 2026-05-26T23:55:18+00:00

I have a problem with the following code: IntegerSet& IntegerSet::unionOfIntegerSets(IntegerSet a){ IntegerSet result; for

  • 0

I have a problem with the following code:

IntegerSet& IntegerSet::unionOfIntegerSets(IntegerSet a){

    IntegerSet result;

    for (int i = 0; i < 100; i++){
        if ((array[i] == 1) || (a.getElement(i) == 1)){
                result.setElement(i, 1);
        }
    }
    return result;
}

The errors are:

  • reference to local variable ‘result’ returned [enabled by default]

  • call of overloaded ‘IntegerSet()’ is ambiguous

Can you tell me what I’m doing wrong? Thank you!

Header file:

#ifndef INTEGERSET_H_
#define INTEGERSET_H_

class IntegerSet{
private:
    int* array;

public:
    IntegerSet();
    IntegerSet(int, int, int, int, int);
    ~IntegerSet();

    int getElement(int);
    void setElement(int, int);

    IntegerSet& unionOfIntegerSets(IntegerSet);
    IntegerSet insertionOfIntegerSets(IntegerSet);
    void setPrint();

};


#endif

What is the workaround for this?

EDIT

IntegerSet IntegerSet::unionOfIntegerSets(IntegerSet a){

    IntegerSet result;

    for (int i = 0; i < 100; i++){
        if ((array[i] == 1) || (a.getElement(i) == 1)){
                result.setElement(i, 1);
        }
    }
    return result;
}

The error is:

  • call of overloaded ‘IntegerSet()’ is ambiguous
  • 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-26T23:55:19+00:00Added an answer on May 26, 2026 at 11:55 pm

    The first error is exactly as it says. You are returning a reference to a local variable.

    result is declared on the stack. It will die after the function ends, therefore whatever references to it will becoming invalid and dangling.

    As for the second error, we need to see the definition of the IntegerSet class to see where the ambiguity is.

    EDIT : You should also define a copy constructor for your class.

    EDIT 2: Okay, I think I figured it out:

    Does your the definition for the second constructor looks something like this?

    IntegerSet::IntegerSet(int a = 0, int b = 0, int c = 0, int d = 0, int e = 0){
    
    }
    

    I tried this and I got the ambiguous overload call that you got.

    In this case, calling the constructor with no parameters can go to either constructor call – hence the ambiguity. So what you should do it get rid of the default value for the first parameter.

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

Sidebar

Related Questions

I have a problem with the following code #include <stdio.h> int main() /* Tidsberäkning
I have the following code which return wmi information (unknown array) For Each objMgmt
I have a problem with the following code: #include <stdio.h> #include <iostream> int main
I have problem with following code. mySpriteArray=[[NSMutableArray alloc] init]; star=[CCSprite spriteWithFile:@22.png]; for(int i=0;i<10; i++)
I have a problem with the following code: for(i = 0;(i - 1)< n;i++)
I have a problem with the following code: protected void onDraw(Canvas canvas) { Paint
I personally have no problem with the following code if (Object foo != null
i am new in JSP,i have some problem with the following code : <%@
Never thought I'd have this problem :) The following snippet of code works in
The following code summarizes the problem I have at the moment. My current execution

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.