Results 1 to 3 of 3

Thread: returning an array

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    returning an array

    I'm trying to return an array, but I'm getting errors when I actually try to use the method.

    The error:
    318 C:\Dev-Cpp\Projects\Histography\main.cpp instantiated from here
    The code:
    Code:
    char* possible_array = hist.get_least_obj_occurances();
    The error:
    151 C:\Dev-Cpp\Projects\Histography\main.cpp invalid conversion from `const char' to `char*'
    The code:
    Code:
    template <typename T> T* Histogram<T>::get_least_obj_occurances()
    {
             typename map<T,int>::iterator ci;
            
             int same_occur = get_same_occurances(0);
             int low = get_least_num_occurances();
            
             T return_array[same_occur];
            
             if (same_occur = 1)
             {
                for (ci=frequency.begin(); ci != frequency.end(); ++ci)
                {
                   if (ci->second == low)
                   {
                     return ci->first;
                   }
                }
             }
             else
             {
                int index = 0;
                for (ci=frequency.begin(); ci != frequency.end(); ++ci)
                {
                   if (ci->second == low)
                   {
                      return_array[index] = ci->first;
                      ++index;
                   }
                }
             }
            
             return return_array;
    }
    It specifically catches on that one bold line.




    I'm creating the array with the following line:
    Code:
    char* possible_array = hist.get_least_obj_occurances();
    Where hist is a histogram object of type char.



    If someone can help me with this it would be much appreciated.

  2. #2
    Lively Member
    Join Date
    Nov 2005
    Posts
    68

    Re: returning an array

    Quote Originally Posted by System_Error
    T return_array[same_occur];
    Stack frame array requires constant size. use T * return_array = new T[same_occur];
    "bla, bla,... exists number M so for each n > M bla, bla..." Exists? Where is it? (Kronecker said...)

  3. #3

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: returning an array

    Thanks. That worked perfectly.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width