Pages: [1]   Go Down
Author Topic: SoftwareSerial as a private class member  (Read 280 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why can't I do like this?

class sim300
{
 private:
   SoftwareSerial* gsm;
...


and then

sim300::sim300(uint8_t RX, uint8_t TX, uint16_t speed)
{
   gsm = new SoftwareSerial(RX, TX);
   gsm.begin(9600);
}

Compiler error: gsm', which is of non-class type 'SoftwareSerial*'
Logged

Offline Offline
Edison Member
*
Karma: 18
Posts: 1172
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't think you need the pointer operator in the declaration.

softwareSerial gsm; should work fine.

http://arduino.cc/en/Reference/SoftwareSerialConstructor
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I do not use pointer then an object needs to be initialized. But there is no empty constructor for SoftwareSerial.

If I try this

class sim300
{
 private:
   SoftwareSerial gsm(2,3);
...

I also get an error

sim300.h : expected identifier before numeric constant
« Last Edit: November 16, 2012, 02:41:22 pm by Raptor5 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Problem resolved. I had to use -> operator with pointer

sim300::sim300(uint8_t RX, uint8_t TX, uint16_t speed)
{
   gsm = new SoftwareSerial(RX, TX);
   gsm->begin(speed);
}
Logged

Pages: [1]   Go Up
Jump to: