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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:07:14+00:00 2026-06-05T06:07:14+00:00

I’m encountering an error I’ve not seen before, that states that reference to things

  • 0

I’m encountering an error I’ve not seen before, that states that reference to things are ambiguous.

I’m writing a small test program that calculates a running median. As the list grows, it recalculates the median. In this case, median means the middle number in the list, (or upper middle). Thus, the median of 7 is 7, the median of 7 and 9 is 9, and the median of 7 3 and 9 is 7.

I’m accomplishing this (I hope) with two dynamic arrays. Initially, the first value is set as the median, and then each number entered is compared to the current median. The median is obtained for calculating the middle element, between two arrays.

The left array is for all values less than the median, and the right array is for all greater. I use insertion sort to order the numbers in each array (it’s great at almost sorted lists).

I just don’t understand the errors I’m getting and or where I’ve gone wrong. I’m fairly new to C++, so I’ve opted for a more simple approach to the issue.

#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

vector<int> left;
vector<int> right;
int leftCount = 0;
int rightCount = 0;
void leftInsertionSort(int);
void rightInsertionSort(int);
void inputNumber(int, int);

int main(int argc, char** argv) {

    int length = 0;
    int value;
    int median;
    string input;

    while (cin >> input) {
        value = atoi(input.c_str());

        inputNumber(value, median);

        if (leftCount > rightCount) {
            median = (((leftCount + rightCount) / 2) + 1);
            cout << left[median];
        } else {
            median = (((leftCount + rightCount) / 2) + 1) - leftCount;
            cout << right[median];
        }
    }

    return 0;
}

void inputNumber(int value, int median) {
    if (leftCount == 0 && rightCount == 0) {
        left[0] = value;
        median = value;
        leftCount++;
    } else
    if (leftCount == 1 && rightCount == 0) {
        right[0] = value;
        if (left[0] > right[0]) {
            right[0] = left[0];
            left[0] = value;
        }
        median = right[0];
        rightCount++;
    } else
    if (value < median) {
        left[leftCount] = value;
    } else {
        right[rightCount] = value;
    }
}

void leftInsertionSort(int lLength)
{
    leftCount++;
    int key, i;
    for(int j = 1; j < lLength; j++)
    {
        key = left[j];
        i = j - 1;
        while (left[i] > key && i >= 0) {
            left[i+1] = left[i];
            i--;
        }
        left[i+1] = key;
    }
}

void rightInsertionSort(int rLength)
{
    rightCount++;
    int key, i;
    for(int j = 1; j < rLength; j++)
    {
        key = right[j];
        i = j - 1;
        while (right[i] > key && i >= 0) {
            right[i+1] = right[i];
            i--;
        }
        right[i+1] = key;
    }
}

The error I seem to be getting is ‘error: reference to ‘left’ 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-06-05T06:07:16+00:00Added an answer on June 5, 2026 at 6:07 am

    Judging from the compiler error I get when trying to compile that, it seems that the namespace std defines names left and right, which you’re also using as variable names. The compiler can’t decide which definition to use, so you get the error. It’s for reasons like these that importing everything from a namespace is frowned upon – you’d be better off either explicitly importing the names you need or using namespace qualifiers.

    In any case, your algorithm seems needlessly complicated. Why not just keep a single vector, push_back into it when you get a new number, place the number at the right index using an insertion algorithm, and then just return the upper middle element of the vector?

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I am writing an app with both english and french support. The app requests

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.