1
votes

Just installed CDT for eclipse, with MinGW gcc. C program "HelloWorld" compiles and runs ok. But tried adding a class declaration in a new .h file to it. Syntax error on class definition. Tried writing my own class declaration and using the new class wiz.

Have used many other C++ ide's other than eclipse. Would like to use eclipse for team integration. What's the eclipse secret to get class declaration to work?

Here's the errors: gcc -O0 -g3 -Wall -c -fmessage-length=0 -o src\main.o ..\src\main.c In file included from ../src/main.c:10:

../src/Logger.h:11: parse error before "Logger"
../src/Logger.h:11: syntax error before '{' token

Here's the class header file "Logger.h" where the error occurs.

#ifndef LOGGER_H_
#define LOGGER_H_

class Logger {
public:
    Logger();
    virtual ~Logger();
};

#endif /* LOGGER_H_ */
2

2 Answers

0
votes

The project created in Eclipse was created as a C project, not a C++ project.  Hence the absence of support for class declaration.

Solution: Created a new project using C++ type, moved the code to the new C++ project, deleted the old C project, renamed the new C++ project to the desired name, and ran clean & rebuild.

0
votes

The indexer can get confused.

I did a Project->C/C++ Index->Rebuild and this cured the issue for me.