Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9197849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:09:42+00:00 2026-06-17T22:09:42+00:00

I’ve been trying to compile a basic program using a library for arduino and

  • 0

I’ve been trying to compile a basic program using a library for arduino and I keep getting this expected class name before ‘{‘ token error. I am novice to c++, so detailed explanation/drop-in solution is much appreciated.

Here is the code :

SerialGSM.h

#ifndef _SerialGSM_H
#define _SerialGSM_H
#include "Arduino.h"
#include <SoftwareSerial.h>

#define SERIALTIMEOUT 2000
#define PHONESIZE 13
#define MAXMSGLEN 160

class SerialGSM : public SoftwareSerial {
public:
  SerialGSM(int rxpin,int txpin);
  void FwdSMS2Serial();
  void SendSMS();
  void SendSMS(char * cellnumber,char * outmsg);
  void DeleteAllSMS();
  void Reset();
  void EndSMS();
  void StartSMS();
  int ReadLine();
  int ReceiveSMS();
  void Verbose(boolean var1);
  boolean Verbose();
  void Sender(char * var1);
  char * Sender();
  void Rcpt(char * var1);
  char * Rcpt();
  void Message(char * var1);
  char * Message();
  void Boot();

  boolean verbose;
  char sendernumber[PHONESIZE + 1];
  char rcpt[PHONESIZE + 1];
  char outmessage[160];
  char inmessage[160];

protected:
  unsigned long lastrec;

};

#endif /* not defined _SerialGSM_H */

SerialGSM.cpp

// SerialGSM version 1.1
// by Meir Michanie
// meirm@riunx.com





// error codes
// http://www.developershome.com/sms/resultCodes2.asp
#include <SerialGSM.h>

SerialGSM::SerialGSM(int rxpin,int txpin):
SoftwareSerial(rxpin,txpin)
{
 verbose=false;
}

void SerialGSM::FwdSMS2Serial(){
  Serial.println("AT+CMGF=1"); // set SMS mode to text
  this->println("AT+CMGF=1"); // set SMS mode to text
  delay(200);
  this->ReadLine();
  Serial.println("AT+CNMI=3,3,0,0"); // set module to send SMS data to serial out upon receipt 
  this->println("AT+CNMI=3,3,0,0"); // set module to send SMS data to serial out upon receipt 
  delay(200);
  this->ReadLine();
}

void SerialGSM::SendSMS(char * cellnumber,char * outmsg){
  this->Rcpt(cellnumber);
  if (verbose) Serial.println(rcpt);
  this->StartSMS();
  this->Message(outmsg);
  Serial.print(outmessage);
  this->print(outmessage);
  this->EndSMS();
  delay(500);
  this->ReadLine();
}

void SerialGSM::SendSMS(){
  if (verbose) Serial.println(rcpt);
  if (verbose) Serial.println(outmessage);
  this->StartSMS();
  Serial.print(outmessage);
  this->print(outmessage);
  this->EndSMS();
  delay(500);
  this->ReadLine();
}

void SerialGSM::DeleteAllSMS(){
  Serial.println("AT+CMGD=1,4"); // delete all SMS
  this->println("AT+CMGD=1,4"); // delete all SMS
  delay(200);
  this->ReadLine();
}

void SerialGSM::Reset(){
  Serial.println("AT+CFUN=1,1"); // Reset Modem
  this->println("AT+CFUN=1,1"); // Reset Modem
  delay(200);
  this->ReadLine();
}


void SerialGSM::EndSMS(){
  this->print(char(26));  // ASCII equivalent of Ctrl-Z
  Serial.println();

  //delay(5 * 1000); // the SMS module needs time to return to OK status
}

void SerialGSM::StartSMS(){

  Serial.println("AT+CMGF=1"); // set SMS mode to text
  this->println("AT+CMGF=1"); // set SMS mode to text
  delay(200);
  this->ReadLine();

  Serial.print("AT+CMGS=");
  this->print("AT+CMGS=");

  this->print(char(34)); // ASCII equivalent of "

  Serial.print(rcpt);
  this->print(rcpt);

  this->println(char(34));  // ASCII equivalent of "

  delay(500); // give the module some thinking time
  this->ReadLine();

}

int SerialGSM::ReadLine(){
  static int pos=0;
  char nc;
  while (this->available()){
    nc=this->read();
    if (nc == '\n' or (pos > MAXMSGLEN) or ((millis()> lastrec + SERIALTIMEOUT)and (pos > 0)) ){
      nc='\0';
      lastrec=millis();
      inmessage[pos]=nc;
     pos=0;
     if (verbose) Serial.println(inmessage);
      return 1;
    }
    else if (nc=='\r') {
    }
    else{
      inmessage[pos++]=nc;
      lastrec=millis();
    }
  }
  return 0;
}


int SerialGSM::ReceiveSMS(){
  static boolean insms=0;
  if (this->ReadLine()){
  // Get the number of the sms sender in order to be able to reply
    if ( strstr(inmessage, "CMT: ") != NULL ){
        insms=1;
        int sf=6;
        if(strstr(inmessage, "+CMT:")) sf++; 
            for (int i=0;i < PHONESIZE;i++){
              sendernumber[i]=inmessage[sf+i];
            }
        sendernumber[PHONESIZE]='\0';
        return 0;
     }else{ 
        if(insms) {
            insms=0;
            return 1;
        }
    }
  }
  return 0;
}


boolean SerialGSM::Verbose(){
    return verbose;
}

void SerialGSM::Verbose(boolean var1){
    verbose=var1;
}

char * SerialGSM::Sender(){
    return sendernumber;
}


char * SerialGSM::Rcpt(){
    return rcpt;
}

char * SerialGSM::Message(){
    return inmessage;
}


void SerialGSM::Sender(char * var1){
    sprintf(sendernumber,"%s",var1);
}


void SerialGSM::Rcpt(char * var1){
    sprintf(rcpt,"%s",var1);
}

void SerialGSM::Message(char * var1){
    sprintf(outmessage,"%s",var1);
}

void SerialGSM::Boot(){
  int counter=0;
  while(counter++ < 15){
    if (verbose) Serial.print(".");
    delay(1000);
  }
  if (verbose) Serial.println();

}

Arduino sketch

#include <SerialGSM.h>
SerialGSM cell(2,3);

boolean sendonce=true;
void setup(){
  Serial.begin(9600);
  // cell.begin(9600);
  cell.Verbose(true);
  cell.Boot();
  cell.DeleteAllSMS();
  cell.FwdSMS2Serial();
 }


void loop(){
  if (cell.ReceiveSMS()){
     Serial.print("Sender: ");
     Serial.println(cell.Sender());
     Serial.print("message: ");
     Serial.println(cell.Message());
     cell.DeleteAllSMS();
  }
}

EDIT:

Here’s complete error message :
/home/agt/arduino/libraries/SerialGSM.h:10: error : expected class-name before ‘{‘ token
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:09:43+00:00Added an answer on June 17, 2026 at 10:09 pm

    You are setting up a mutual inclusion between your header files “arduino.h” and “serialgsm.h”. Resolve that by using forward declarations and the error will most likely disappear (or you will at least get a different one).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.