Sign in to follow this  
AIRmichael

compiling error

Recommended Posts

Hey, I am trying to compile the following in the redhat terminal: main.c Test.c Test.h gcc main.c Test.c -o test But what I get is the following: Test.h:1: error: syntax error before "Test" Test.h:2: error: syntax error before '{' token In file included from Test.c:1: Test.h:1: error: syntax error before "Test" Test.h:2: error: syntax error before '{' token Test.c:3: error: syntax error before ':' token Does any one know how to fix this? Test.c contains: #include "Test.h" void Test::bla() { int a = 0; } and Test.h contains: class Test { public: void Test::bla(); }; and the main.c contains "#include Test.h" What is wrong with it? Do I have to make a seperate makefile or something? If so, how would that be possible? Greetings, Michael L.

Share this post


Link to post
Share on other sites
Try declaring your class like this instead:


class Test
{
public:
void bla(); //<--- no "Test::" before function name
};



and see if that does the trick, you only need the class_name:: in source files (.cpp), not in headers files.

Share this post


Link to post
Share on other sites
Quote:
Original post by Spudder
Try declaring your class like this instead:


class Test
{
public:
void bla(); //<--- no "Test::" before function name
};



and see if that does the trick, you only need the class_name:: in source files (.cpp), not in headers files.


I fixed that now, but I still have the same error :(

Share this post


Link to post
Share on other sites
Try replacing gcc on the command line with g++. I think (although I may be wrong) that vanilla gcc only deals with straight C unless you fire strange command line switches at it. g++ is the C++ version.

Share this post


Link to post
Share on other sites
Quote:
Original post by Hamster
Try replacing gcc on the command line with g++. I think (although I may be wrong) that vanilla gcc only deals with straight C unless you fire strange command line switches at it. g++ is the C++ version.


Thx alot, I had to do some adjustments (My linux didnt recognize a function called exit (useing a tutorial from nehe) so i had to remove that, and link only the GLUT library manually.

So this works:

g++ -o test main.c Test.c -lglut

Share this post


Link to post
Share on other sites
Sign in to follow this