File header errors

Hello. I couldn't solve this problem as I don't understand why would the complier produce such error messages for this header.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef golf_H
#define golf_H


const int Len = 40;
struct golf
{
    char fullname[Len];
    int handicap;
};

void setgolf (golf & g, const char * name, int hc);

int setgolf (golf & g);

void handicap (golf & g, int hc);

void showgold (const golf & g);


#endif  


Error:
 
error: expected ')' before '&' token


This error appeared for all of my functions containing the '&' character.

Also, there's another error which states:
 
error: variably modified 'fullname' at file scope

I am not sure what it meant?

Thanks!
What compiler? With GCC 4.9.2 I get no errors.
You need to compile the code as C++ for it to work. C doesn't have references.
I'm using 4.7.1, which came with codeblocks 13.12

EDIT: How do I compile it in C++? I saved the files as "main.cpp", "golf.cpp" and "golf.h" and clicked compile, but the same errors as follows.
Last edited on
Maybe you are already compiling it as C++, I was just guessing.

Do you get the error if you only compile golf.h? If it compiles fine on its own then the problem must be caused by the other files that include the it.
Actually golf.h shouldn't be compiled, it should be #included.

How did you create your project?

Here's my code in the project:
1
2
3
4
5
6
7
8
9
//for golf.h (erroneous; placed in "Headers")

#ifndef golf_H
#define golf_H


enum {Len = 40}; //when I changed to this, there was no "variably error".
...
#endif 

1
2
3
4
5
6
7
8
9
10
//For main.cpp (placed in "Sources")

#include <iostream>
#include "golf.h"

int main()
{
    ...
    return 0;
}

1
2
3
4
5
6
//For golf.cpp (placed in "Sources")

#include "golf.h"
#include <iostream>
#include <cstring>
...


EDIT: Okay, I used a different compiler (VS 2013) and no errors was found. I'm not sure why either.
Last edited on
Actually golf.h shouldn't be compiled, it should be #included.

Yes, compiling it as part of the build process is unnecessary, but it should still be possible to compile it on its own without errors otherwise something is wrong.
Last edited on
Topic archived. No new replies allowed.