Thread: templated quick sort error

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    18

    templated quick sort error - solved

    Hey there. I'm getting some odd errors trying to work on a quick sort example. It seems like I'm not using my templated parameters correctly. It's making T an int* when I want T to be just int. I thought by using <class T> and <T* arr ... I would be able to get a pointer of type T. When I call quick sort I'm passing a reference to T, so that I can change the values in the sorted arrays. I'm guessing this is the error, but ... yeah. I've rambled enough.

    -edit-

    So, in case anyone googles for these errors ...

    don't pass arrays by address into templated functions. The pointers seem to work just fine.

    Problem solved.


    Code:
    "exampleSort.c", line 88: error: initialization with "{...}" expected for
              aggregate object
            T pivot = array[startIndex];//pivot element is the leftmost element
                      ^
              detected during instantiation of
                        "void QuickSort(T *, int, int) [with T=int [10]]"
    
    "exampleSort.c", line 95: error: no instance of function template "SplitArray"
              matches the argument list
                argument types are: (int (*)[10], int [10], int, int)
                    splitPoint = SplitArray(array, pivot, startIndex, endIndex);
                                 ^
              detected during instantiation of
                        "void QuickSort(T *, int, int) [with T=int [10]]"
    
    "exampleSort.c", line 99: error: expression must be a modifiable lvalue
                    array[splitPoint] = pivot;
                    ^
              detected during instantiation of
                        "void QuickSort(T *, int, int) [with T=int [10]]"
    Last edited by gesangbaer; 07-04-2010 at 01:39 AM. Reason: Solved

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You can pass arrays by address into templated functions.
    Code, please.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM