SoftwareSerial object within a class


I have a question regarding the implementation of software serial object within a class.

I’m attempting to create a class that handles all serial communications. The purpose of this class is to create a SerialInterface object. However, I’m having a hard time configuring the SoftwareSerial object to exist within this new class.

I’ve attempted creating ‘SoftwareSerial softSerial(10,11)’ as a private object in the SerialInterface class, but I keep receiving error messages.

Ideally, I would like the SoftwareSerial object to be hidden inside the SerialInterface object away from the main sketch. Is there any way to do this?

Please refer to the screen captured code. The error message is posted below.

Arduino: 1.6.5 (Windows 7), Board: “Arduino Uno”

SensorSerialInterface.h:32:30: error: expected identifier before numeric constant
SoftwareSerial _softSerial(10,11);
/SensorSerialInterface.h:32:30: error: expected ‘,’ or ‘…’ before numeric constant
Error compiling.


Please post the code of your library files and main program. Use code tags (the </> button on the button bar above the smileys).

Im going to guess it is because you are defining the object instead of declaring it.

Try removing the (10,11) inside the class declaration and instead write this in your constructor for your SerialInterface object.

_softSerial = new SoftwareSerial(10,11);