Cant compile through WEB IDE [SOLVED]

I was going to build a library for the community and thought I would use the WEB IDE, I generally use Eclipse.

I was just putting a couple classes together, I like to build a skeleton then compile before adding meat but it wont compile.

Here are the Classes H an CPP

Header:

class 16RelayController{
public:
    //Constructor
    void 16RelayController(void);
    //Set Address.  Indicate status of jumpers on board.  Send 0 for not installed, send 1 for installed
    void setAddress(int A0, int A1, int A2);
    //Turn on Relay
    void turnOnRelay(int Relay);
    //Turn off Relay
    void turnOffRelay(int Relay);
    //read relay status
    void readStatus();
};

Implementation:

//Blank Comment
#include "16RelayController.h"

//Constructor
16ChannelRelayController::16ChannelRelayController(){
}

void 16ChannelRelayController::setAddress(int A0, int, A1, int A2){
    
}

void 16ChannelRelayController::turnOnRelay(int relay){
    
}

void 16ChannelRelayController::turnOffRelay(int relay){
    
}

void 16ChannelRelayController::readStatus(){
    
}

Console Error Log:

In file included from 16RelayController.cpp:2:0:
16RelayController.h:1:7: error: expected identifier before numeric constant
class 16RelayController{
^
16RelayController.h:1:7: error: expected unqualified-id before numeric constant
16RelayController.cpp:5:1: error: expected unqualified-id before numeric constant
16ChannelRelayController::16ChannelRelayController(){
^
16RelayController.cpp:8:6: error: expected unqualified-id before numeric constant
void 16ChannelRelayController::setAddress(int A0, int, A1, int A2){
^
16RelayController.cpp:12:6: error: expected unqualified-id before numeric constant
void 16ChannelRelayController::turnOnRelay(int relay){
^
16RelayController.cpp:16:6: error: expected unqualified-id before numeric constant
void 16ChannelRelayController::turnOffRelay(int relay){
^
16RelayController.cpp:20:6: error: expected unqualified-id before numeric constant
void 16ChannelRelayController::readStatus(){
^
make: *** [16RelayController.o] Error 1

Tried adding blank comment lines to the top as suggested on some other threads but nothing is working. This compiles just fine in Eclipse. Am I missing something here?

If you are trying to compile this in a sketch (.ino file) then you need to turn off the Spark preprocessor with a pragma. The preprocessor does not like class definitions in .ino files.

If you have this code in .h and .cpp tabs already, it should work.

You might to protect your header against being included more than once with an #ifndef or #pragma.

Hi @IOTrav,

Class names, and all identifiers in C/C++ can’t start with a digit, so you’ll need to rename the class to place the digits afterwards, e.g.

RelayController16Channel

2 Likes

Thanks @bko and @mdma

These were .h and .cpp files. Problem was as Matthew suggested, could not name classes starting with a number. All is working now.

Thanks guys

1 Like