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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:50:39+00:00 2026-06-09T02:50:39+00:00

Hey I’m making a generic implementation of an ArrayList in C++ and part of

  • 0

Hey I’m making a generic implementation of an ArrayList in C++ and part of it is implementing MergeSort, but now that I’ve started testing it I’m running into an odd problem. In my tests I’m using type int for simplicity, and on the second function signature below I’m getting the error:

initializing argument 1 of 'T* ArrayList<T>::mergeSort(T*, int) [with T = int]' [-fpermissive]

Then on the recursive calls in the second function I get this error:

invalid conversion from 'int' to 'int*' [-fpermissive]

I don’t understand why it thinks I’m trying to convert from an int to an int…shouldn’t both be of type int* !? I’m kind of a noob to C++, and especially generics in C++ (although I’m well versed in Java) so any helpful pointers (no pun intended) are appreciated!

/**
 * Runs merge sort on this ArrayList<T>. Interface function to the central,
 * recursive, merge sort function.
 */
template<class T>
void ArrayList<T>::mergeSort() {

    mergeSort(array, size);
}

/**
 * Runs merge sort on the passed in array. Recursive.
 *
 * @param array the array to sort.
 * @param arraySize the size of the array that is to be sorted.
 * @return the sorted array.
 */
template<class T>
T* ArrayList<T>::mergeSort(T* array, int arraySize) {

    T* returnArray = array;

    //If the arraySize isn't 1, recurse. Otherwise return the single element array.
    if (arraySize != 1) {

        returnArray = new T[arraySize];

        //Split arrays further. Recurse.
        returnArray = mergeSort(array[0], arraySize / 2);
        returnArray += arraySize / 2;
        returnArray = mergeSort(array[arraySize / 2], arraySize - (arraySize / 2));
    }

    return returnArray;
}
  • 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-09T02:50:41+00:00Added an answer on June 9, 2026 at 2:50 am

    In your two recursive calls, you are not passing pointers, you are passing the values in the array at those indices.

    if (arraySize != 1) {
    
            returnArray = new T[arraySize];
    
            //Split arrays further. Recurse.
            returnArray = mergeSort(array[0], arraySize / 2);
            returnArray += arraySize / 2;
            returnArray = mergeSort(array[arraySize / 2], arraySize - (arraySize / 2));
        }
    

    Change your recursive calls to either:

    returnArray = mergeSort(&array[0], arraySize / 2);
    returnArray = mergeSort(&array[arraySize / 2], arraySize - (arraySize / 2));
    

    or:

    returnArray = mergeSort(array, arraySize / 2);
    returnArray = mergeSort(array + (arraySize / 2), arraySize - (arraySize / 2));
    

    I’m not clear on what your first error is, it looks like you’ve cut off part of the error message.

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

Sidebar

Related Questions

Hey i am making an Ordered ArrayList for C++ and one of functions used
Hey I just started dabbling with android programming, and from my short period of
hey guys having this really simple problem but cant seem to figure out have
Hey guys I wanted to create a JScrollPane but it won't work... and I
Hey I'm building an app that will allow a user to log into a
Hey I thought about writing a function that prompts me in certain situations (perl
Hey everyone I have a basic search function here that allows me to search
Hey guys, sorry I'm kind of new to programming, but I had a small
Hey guys I am making a terminal application using Swing and Apache Commons. I
Hey guys I am new to android development, I am currently making an application.The

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.