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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:11:35+00:00 2026-05-26T15:11:35+00:00

When I call merge_sort I get a string of errors as such the most

  • 0

When I call merge_sort I get a string of errors as such the most readable is:

no matching function call to dynamic_array<int>::dynamic_array()

Does having a base class instantiate a sub class cause that sub-class to re-instantiate the calling base class?

This was my first guess.

// Calling main function

#include "c_dynamic_array.cpp"
int main()
  {
  dynamic_array<int> d1(20);
  d1.order();cout << d1 << endl;
  d1.rorder();cout << d1 << endl;
  d1.randorder();cout << d1 << endl;
  d1.merge_sort();cout << d1 << endl; // This line starts a string of errors
  }

// Dynamic Array Class and Merge Inner (merge sort) Class

#include "c_include.cpp"

/*
Dynamic Array
*/

using namespace std;
template <typename> class merge_inner;

template <class T> class dynamic_array
  {
  protected:
    T* array;
  public:
    int size;
    void rorder();
    void order();
    void randorder();
    void print_operator(ostream&)const;
    dynamic_array(int sizein)
      {
      size=sizein;
      array=new T[size]();
      }
    void merge_sort()
      {
      merge_inner<T> M1;
      }
  };
template <class T> void dynamic_array<T>::print_operator(ostream &os=cout)const
  {
  for (int i = 0; i < size; i++) os << array[i] << endl;
  }
template <class T> void dynamic_array<T>::randorder()
  {
  srand(time(NULL));
  int *ap;
  for(ap=array;ap!=array+size;++ap){*ap=rand()%size;} 
  }
template <class T> void dynamic_array<T>::order()
  {
  int *ap,i=0;
  for(ap=array;ap!=array+size;++ap)                                             
    { 
    *ap=i;
    ++i;        
    } 
  }
template <class T> void dynamic_array<T>::rorder()
  {
  int *ap,i=size-1;
  for(ap=array;ap!=array+size;++ap)                                             
    { 
    *ap=i;
    --i;        
    } 
  }
template<class T> ostream& operator<<(ostream& stream, dynamic_array<T> const& data) 
  { 
  data.print_operator(stream);
  return stream; 
  }   

/*
Merge Sort
*/

template <class T> class merge_inner : public dynamic_array <T>
  {
  using dynamic_array<T>::array;
  private:
    const static int size;
    T *scratch;
    void flip_if_unordered(int &x, int &y)
      {
      if(array[x]>array[y])
        {
        int tmp=array[x];
        array[x]=array[y];
        array[y]=tmp;
        }
      }
    void merge_algo(int &left, int &right_begin, int &right)
      {
      int iter,iter_left=left,iter_right=right_begin;  
      for(iter=left;iter<=right;++iter)
        {
        if( (iter_right>right) || ((iter_left < right_begin) && (array[iter_left]<=array[iter_right])))
          {
          scratch[iter]=array[iter_left];
          ++iter_left;
          }
        else
          {
          scratch[iter]=array[iter_right];
          ++iter_right;
          }
        }
      for(iter=left;iter<=right;++iter){array[iter]=scratch[iter];}
      }
    void merge_recurse(int left,int right)
      {
      int left_end=(left+((right-left)/2)); 
      int right_begin=left_end+1;  
      if(((left+1)==right)){flip_if_unordered(left,right);return;}
      else if ((left==right)){return;}
      else
        { 
        merge_recurse(left,left_end);               
        merge_recurse(right_begin,right);  
        merge_algo(left,right_begin,right);
        }   
      }
  public:
    merge_inner()
      {
      scratch = new T[size]();
      if(scratch != NULL){merge_recurse(0, size);}
      }
  };
/*Quick Sort
    void quick_sort()
      {
      quick_recurse(0,size);
      }
    void quick_recurse(int left, int right) 
      {  
      int l = left, r = right, tmp;
      int pivot = array[(left + right) / 2];
      while (l <= r)
        {
        while (array[l] < pivot)l++;
        while (array[r] > pivot)r--;
        if (l <= r) 
          {
          tmp = array[l];
          array[l] = array[r];
          array[r] = tmp;
          l++;
          r--;
          }
        }
      if (left < r)quick_recurse(left, r);
      if (l < right)quick_recurse(l, right);
      }  
*/
  • 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-26T15:11:35+00:00Added an answer on May 26, 2026 at 3:11 pm

    dynamic_array seems to be missing a default constructor, and since it has a custom constructor the compiler will not provide one. Add this to your class:

      dynamic_array()
      {
          size = 0;
          array = new T[0](); // or NULL, but note that new T[0] will be != NULL
      }
    

    Alternatively, provide a default sizein for your existing constructor so that it can be used as a default constructor as well:

    dynamic_array(int sizein = 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I call my JavaScript function. Why do I sometimes get the error 'myFunction is
I call a javascript function from a textbox by using OnKeyPress=clickSearchButton() Here is my
I call the following function with a mouseover event but it's not working. My
I call an ajax enabled wcf service method , <script type=text/javascript> function GetEmployee() {
I have a function that I want to call from within a class method.
Call me a 'n00b', but I am new to creating Script Controls. I want
I call this a flash meeting, but maybe there is another more appropriate name.
A call to clear on a QByteArray generates the following exception: * glibc detected
I call addNotify() method in class that I posted here. The problem is, that
I call: [[ UIApplication sharedApplication ] setIdleTimerDisabled: YES ] on the applicationDidFinishLaunching event.. I

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.