Recurring C++ Error

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Greetings -

 

As I work on a C++ project, this error has become the single most frequent one, and I don't know what it is trying to tell me or how to identify the cause. Pretty sure that it is a C++ error rather than a simple C syntax error (eg, badly formed if() statement, for example). So, here is the header file where the IDE points to the errors (two which likely have the same cause):

 

#ifndef ORE_SERIAL_H
#define ORE_SERIAL_H

#include <avr/io.h>
#include <stdint.h>

#include "ArduinoConstants.h"

#define PRINT_CR	1
#define PRINT_LF	2
#define PRINT_CRLF	3

#define PRINT_EOL	PRINT_CRLF
	
//base designators for print() functions
#define BIN  2		//binary
#define OCT  8          //octal
#define DEC  10		//decimal
#define HEX  16		//hexadecimal

#define BITS8  (1<<UCSZ01)|(1<<UCSZ00)

#define STOP1  0

#define PARITYN	0

#define SERIAL_8N1  BITS8|PARITYN|STOP1   // (the default)

class ORE_Serial {
	
	private:
	uint8_t RxIdx;
	char * RxPtr;

	char RxBuf[64];
	char NumBuf[34];  //for 32bit ascii binary string plus null terminator
	uint16_t printEOL ( );

	public:
	
	void begin(uint16_t,uint8_t);
	void end();
	//character
	uint16_t print( char );
	uint16_t println( char );
	//string
	uint16_t print( char * );
	uint16_t println( char * );
	//8-bit number

	//16-bit number
	uint16_t print( int16_t , uint8_t );
	uint16_t println( int16_t , uint8_t );
	uint16_t print( uint16_t , uint8_t );	
	uint16_t println( uint16_t , uint8_t );
	uint16_t print( int16_t );
	uint16_t println( int16_t );
	uint16_t print( uint16_t );
	uint16_t println( uint16_t );
	
	//32-bit number
	uint16_t print( int32_t , uint8_t );
	uint16_t println( int32_t, uint8_t );
	uint16_t print( int32_t );	
	uint16_t println( int32_t);
	uint16_t print( uint32_t , uint8_t );
	uint16_t println( uint32_t, uint8_t );
	uint16_t print( uint32_t );	
	uint16_t println( uint32_t);
	
	//double (floating point)
	uint16_t print( double , uint8_t );
	uint16_t println( double , uint8_t );
	uint16_t print( double );
	uint16_t println( double );

};	
	
#endif //ORE_SERIAL_H

There are other defines that have been commented out, attempting to remove them as possible error sources. The errors point to the line 

class ORE_Serial {

The Error List shows:

Severity

Code

Description

Project

File

Line

Error

 

unknown type name 'class'

ORE_Test

C:\Users\Jim\Dropbox\FloodWatcher\Code\ORE_Test\ORE_Test\ArduinoCompatibility\ORE_Serial.h

90

Error

 

expected '=', ',', ';', 'asm' or '__attribute__' before '{' token

ORE_Test

C:\Users\Jim\Dropbox\FloodWatcher\Code\ORE_Test\ORE_Test\ArduinoCompatibility\ORE_Serial.h

90

The Output shows:

 

------ Build started: Project: ORE_Test, Configuration: Debug AVR ------

Build started.

Project "ORE_Test.cppproj" (default targets):

Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').

Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project "C:\Users\Jim\Dropbox\FloodWatcher\Code\ORE_Test\ORE_Test\ORE_Test.cppproj" (target "Build" depends on it):

    Task "RunCompilerTask"

        Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils

        C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all 

        Building file: ../ArduinoCompatibility/ORE_Serial.cpp

        Invoking: AVR8/GNU C Compiler : 4.9.2

        "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-g++.exe" -funsigned-char -funsigned-bitfields -DDEBUG  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\include"  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\gcc\dev\atmega328p" -c -MD -MP -MF "ORE_Serial.d" -MT"ORE_Serial.d" -MT"ORE_Serial.o"   -o "ORE_Serial.o" "../ArduinoCompatibility/ORE_Serial.cpp" 

        Finished building: ../ArduinoCompatibility/ORE_Serial.cpp

        Building file: .././main.cpp

        Invoking: AVR8/GNU C Compiler : 4.9.2

        "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-g++.exe" -funsigned-char -funsigned-bitfields -DDEBUG  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\include"  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\gcc\dev\atmega328p" -c -MD -MP -MF "main.d" -MT"main.d" -MT"main.o"   -o "main.o" ".././main.cpp" 

        Finished building: .././main.cpp

        Building file: ../ArduinoCompatibility/ORE_Digital.c

        Invoking: AVR8/GNU C Compiler : 4.9.2

        "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\include"  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\gcc\dev\atmega328p" -c -std=gnu99 -MD -MP -MF "ORE_Digital.d" -MT"ORE_Digital.d" -MT"ORE_Digital.o"   -o "ORE_Digital.o" "../ArduinoCompatibility/ORE_Digital.c" 

        In file included from ../ArduinoCompatibility/ArduinoCompatibility.h:27:0,

                         from ../ArduinoCompatibility/ORE_Digital.c:32:

C:\Users\Jim\Dropbox\FloodWatcher\Code\ORE_Test\ORE_Test\ArduinoCompatibility\ORE_Serial.h(90,1): error: unknown type name 'class'

         class ORE_Serial {

         ^

C:\Users\Jim\Dropbox\FloodWatcher\Code\ORE_Test\ORE_Test\ArduinoCompatibility\ORE_Serial.h(90,18): error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token

         class ORE_Serial {

                          ^

        make: *** [ORE_Digital.o] Error 1

    Done executing task "RunCompilerTask" -- FAILED.

Done building target "CoreBuild" in project "ORE_Test.cppproj" -- FAILED.

Done building project "ORE_Test.cppproj" -- FAILED.

 

Build FAILED.

========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

I HAD been able to build this project, successfully, until removing some tests for the presence or absence of a specific define that were sprinkled through all of the header files.

 

At this point, I have no clue about where to look. Suggestions, hints, references to previous threads where someone already gave me the answer to this :=) are all welcome.

 

Many thanks

jim 

This topic has a solution.

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Thu. Aug 3, 2017 - 07:52 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you include that header file into a C file, then of course you get errors. C does not know about 'class'.

Enclose the class definition in '#ifdef __cplusplus', then you can use it in C files.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It is included in a cpp file and this is a cpp project.

 

Other classes seem to work OK. Hmm, actually, ALL of the classes are suddenly throwing the same error. This one appears representative. This is in a cpp project that used to build.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Thu. Aug 3, 2017 - 06:05 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

        "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\include"  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega328p -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.0.90\gcc\dev\atmega328p" -c -std=gnu99 -MD -MP -MF "ORE_Digital.d" -MT"ORE_Digital.d" -MT"ORE_Digital.o"   -o "ORE_Digital.o" "../ArduinoCompatibility/ORE_Digital.c

        In file included from ../ArduinoCompatibility/ArduinoCompatibility.h:27:0,

                         from ../ArduinoCompatibility/ORE_Digital.c:32:

C:\Users\Jim\Dropbox\FloodWatcher\Code\ORE_Test\ORE_Test\ArduinoCompatibility\ORE_Serial.h(90,1): error: unknown type name 'class'

         class ORE_Serial {

         ^

ORE_Digital.c is a C file.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ahh, it appears that I have my #includes messed up! Thanks for catching that.

 

That was, indeed, the problem. I had a generic "includer" that included a whole bunch of header files. Unfortunately, I did not pay attention to which were C headers and which were C++ headers. That is now fixed. Again, thanks.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Thu. Aug 3, 2017 - 06:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It seems odd to me to have a class definition header file with anything else in the file.  But ya gotta learn and maybe you invented a new and better programming scheme.  wink

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Some people use .hpp (to match .cpp) to differentiate C++ headers from C .h files.
.
Of course if all source is .cpp then you know all .h files are C++ headers anyway.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, Cliff -

 

That might actually provide a good reminder of what-is-what in a mixed environment.

 

This is also a lesson in the need to read the output report more carefully :)

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Sat. Aug 5, 2017 - 09:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Some people use .hpp (to match .cpp) to differentiate C++ headers from C .h files.
Arrrrg.

I hate .cpp , but it, like Windows, seems to have conquered the world.

.cpp makes me think C PreProcessor.

When I have a choice, I use .cc for top-level C++ files and .hh for C++-only headers.

International Theophysical Year seems to have been forgotten..
Anyone remember the song Jukebox Band?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I use .cpp out of habit.

 

I found something on the internet that claims to give the options for Microsoft and GNU and several other compilers.  Those are the only 2 compilers I use so I have 3 choices.  I'll stick with .cpp because breaking habits is extra work.

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And just one common denominator. So .cpp it is then ;-)