Click here to Skip to main content
15,909,530 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello guys,

i wrote a few header files, but all of them give similiar errors. Can you help me ?

Here is the header file:
C++
#ifndef insertion_sort
#define insertion_sort
    void insertion_sort(int array[], int array_SIZE);

    void insertion_sort(int array[], int array_SIZE){
        int i, j, carry;
            for(i=1; i<array_size>< i++){
                carry=array[i];
                j=i;
                    while(j>0 && array[j-1]>carry){
                        array[j]=array[j-1];
                        j--;
                    }
                array[j]=carry;
            }
    }

#endif // insertion_sort

and there is the errors:

function prototype and function definitions are giving same errors.

expected unqualified-id before int;
expected ')' before 'int'
Posted
Updated 30-Dec-13 9:28am
v2

1 solution

You should not use the name of your function or class as the #define that wraps the header file. The line "#define insertion_sort" is telling the preprocessor to replace all the occurrences of "insertion_sort" with an empty string and causing the strange error messages.

Try using
C++
#ifndef insertion_sort_h
#define insertion_sort_h
instead, or if you're using Visual C++ you could use
C++
#pragma once
instead of the guard definition.
 
Share this answer
 
Comments
Ron Beyer 30-Dec-13 16:35pm    
+5, good catch on the redefine and the function name being the same. Its a hard error to catch.
Albert Holguin 30-Dec-13 16:44pm    
+5, I would go with the _h option... pragma comments aren't exactly cross compilation friendly

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900