Thread: c++ error: variable of field <functionName> declared void

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    1

    c++ error: variable of field <functionName> declared void

    Im doing a quicksort overload function for bool, char, long.. etc. but once I compile it, it says the error mentioned in the main function. It runs perfectly when it's not overloaded. here's the code:

    main.cpp
    Code:
    void sortArray(charArray, 0, size-1);
    void sortArray(boolArray, 0, size-1);
    void sortArray(intArray, 0, size-1);
    void sortArray(longArray, 0, size-1);
    void sortArray(floatArray, 0, size-1);
    void sortArray(doubleArray, 0, size-1);
    sort.cpp
    Code:
    void printArr(int* arr, int n);
    int splitArr(int* arr, int pivot, int start, int end);
    void sortArray(int* arr, int start, int end);
    void swap(int &a, int &b);
    
    void printArr(int* arr, int n)
    {
        int i;
         
        for( i = 0; i < n; i++) cout<<arr[i]<<'\t';
    
    
        cout << endl;
    }
    
    
    void sortArray(int* arr, int start, int end)
    {
        int pivot = arr[start];                    
        int splitPoint;
        
        if(end > start)                         
                                                          
                                                          
        {
            splitPoint = SplitArray(arr, pivot, start, end);
                                                          
            arr[splitPoint] = pivot;
            sortArray(arr, start, splitPoint-1);   
            sortArray(arr, splitPoint+1, end);     
        }
    }
    
    
    int splitArr(int* arr, int pivot, int start, int end)
    {
        int leftBoundary = start;
        int rightBoundary = end;
        
        while(leftBoundary < rightBoundary)               
        {
             while( pivot < arr[rightBoundary]          
                    && rightBoundary > leftBoundary)      
             {
                  rightBoundary--;                        
             }
             swap(arr[leftBoundary], arr[rightBoundary]);
             
             while( pivot >= arr[leftBoundary]          
                    && leftBoundary < rightBoundary)      
             {
                  leftBoundary++;                         
             }
             swap(arr[rightBoundary], arr[leftBoundary]);
        }
        return leftBoundary;                              
                                                          
    }
    
    
    
    void swap(int &a, int &b)
    {
        int temp;
        temp = a;
        a = b;
        b = temp;
    }

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    void sortArray(charArray, 0, size-1);
    void sortArray(boolArray, 0, size-1);
    void sortArray(intArray, 0, size-1);
    void sortArray(longArray, 0, size-1);
    void sortArray(floatArray, 0, size-1);
    void sortArray(doubleArray, 0, size-1);
    Is this supposed to call the function or declare function prototypes? If it's supposed to call the function, then remove the "void." You don't specify return type when calling functions.
    You might also want to look at templates later. It allows a function to take an arbitrary type, and so you can collapse all your functions into one (I'm assuming you have several).
    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. A variable has to be declared before use
    By Ramcin Oudishu in forum C++ Programming
    Replies: 1
    Last Post: 08-26-2014, 06:16 AM
  2. "Variable Or Field Declared Void" And Other Errors
    By Niki Robbers in forum C Programming
    Replies: 7
    Last Post: 03-29-2014, 01:57 AM
  3. Replies: 4
    Last Post: 12-17-2011, 06:15 PM
  4. "variable or field declared void"
    By Treborh in forum C++ Programming
    Replies: 13
    Last Post: 02-06-2010, 03:33 PM
  5. Passing a variable in void to another void function
    By stevedawg85 in forum C++ Programming
    Replies: 5
    Last Post: 05-05-2006, 06:17 PM

Tags for this Thread