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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:24:07+00:00 2026-06-08T09:24:07+00:00

Hey i am making an Ordered ArrayList for C++ and one of functions used

  • 0

Hey i am making an Ordered ArrayList for C++ and one of functions used to insert a number and replace a space in the ArrayList with this number is not working. Im getting an error message saying : Error C2065: index_undeclared identifier;

Here is my code:

OrderedArray.cpp

#include"OrderedArray.h"//To allow the use of Array.h Header file.
#include<iostream>
using namespace std;// To allow the use of the standard library.

int main()//Main method for OrederedArray.cpp.
{
    //Creating an array with the Datatype in from the template.
    OrderedArray<int> intArray(10);
    //Filling the Array(intArray)with elements from 1-10.
    intArray[0] = 1;
    intArray[1] = 200;
    intArray[2] = 323;
    intArray[3] = 976;
    intArray[4] = 545;
    intArray[5] = 767;
    intArray[6] = 234;
    intArray[7] = 123;
    intArray[8] = 456;
    intArray[9] = 789;
    
    intArray.printArray();
    intArray.Remove(7);
    intArray.printArray();
    intArray.Insert(1232,1);
    intArray.printArray();



getchar();
getchar();
}

OrderedArray.h

//Header file for OrderedArray.cpp.
#ifndef ORDEREDARRAY_H
#define ORDEREDARRAY_H
//Template for use with the Array's data type.
template<class Datatype>
//***************************************************************************************
class OrderedArray
{

private:
    
//Member Variables.
    int size;
    int grow_size;
    int num_elements;
    Datatype* m_array;
//***************************************************************************************


public:
//Constructor.
    OrderedArray( int p_size)
    {
        m_array = new Datatype[p_size];
        size = p_size;
    }
//***************************************************************************************




//Destructor.
    ~OrderedArray()
    {
        if( m_array!= 0 )
            delete[] m_array;
        m_array= 0;
    }
//***************************************************************************************

//Access Operator: Syntax to allow the use of editing.
    Datatype& operator[] ( int p_index)
    {
        return m_array[p_index];
    }
//***************************************************************************************

//Functions.
    void ArrayFunction( int* p_array)
    {
    p_array[0] = 10;
    }
//Print Function: To print out all elemenst in the Array.
    void printArray()
    {
        for(int i=0;i< size;i++)
        {
            cout << "Position: " <<m_array[i]<<endl;
        }


    }
//***************************************************************************************

//Resize Function: To resize the Array.
    void Resize( int p_size)
    {
        Datatype* newarray = new Datatype[p_size];
        if( newarray== 0 )
            return;
        int min;
        if( p_size< size)
            min = p_size;
        else
            min = size;
        int index;
        for( index = 0; index < min; index++ )
            newarray[index] = m_array[index];
        m_size= p_size;
        if( m_array!= 0 )
            delete[] m_array;
        m_array= newarray;
    }
//***************************************************************************************

//Remove Function: To remove an element in an Array.
    void Remove( int p_index)
    {
        int index;
        for( index = p_index+ 1; index < size; index++ )
            m_array[index -1] = m_array[index];
    }
//***************************************************************************************
    //Size Function: To get the size of the Array.
    int Size()
    {
        return size;
    }
//***************************************************************************************
//Insert Function: To insert an element into the array between points in the index.
    void Insert( Datatype p_item, int p_index)
    {
        for(int index = size-1; index > p_index; index—)
        m_array[index] = m_array[index -1];
        m_array[p_index] = p_item;
    }
//***************************************************************************************
//***************************************************************************************


};

#endif 
  • 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-08T09:24:10+00:00Added an answer on June 8, 2026 at 9:24 am

    You say this:

        void Insert( Datatype p_item, int p_index)
    {
        for(int index = size-1; index > p_index; index-)
        m_array[index] = m_array[index -1];
        m_array[p_index] = p_item;
    }
    

    When it should be this:

    void Insert( Datatype p_item, int p_index)
    {
        for(int index = size-1; index > p_index; index--)
        m_array[index] = m_array[index -1];
        m_array[p_index] = p_item;
    }
    

    Notice the index– at the end of the for statement in the revised code snippet.

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

Sidebar

Related Questions

Hey I've been making a quiz on php and mysql... I've used the CURRENT_TIMESTAMP
Hey guys. This is a follow-on from this question : After getting the right
Hey Frens I am making one project in asp.net C#, in which i have
Hey, I'm making a script that checks if a specified string matches the one
hey guys, I have no luck making a simple background image animation working without
Hey guys..this is kind of a weird question but I'm making a webapp in
Hey guys, This is my first time making an app with any kind of
Hey people out there.. Im working on making a application with tabview where in
Hey guys I'm in the process of making this website here: http://craigmarkdrums.com (bare in
Hey I'm making a quiz application and I need to pass an ArrayList of

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.