Library Issue

Hi there.
I am busy creating my own library.
I have started with the header and source file of a class that will be used as an object in my sketch.

But when I call an instance of this class in my sketch it gives me the following error:
UserInput.cpp:9: error: expected initializer before 'getSerial’

Below is my code so far. The sketch is not much as I want to keep it simple in order to see if my library is linked correctly to my sketch.

header file:

#ifndef UserInput_h
#define UserInput_h
#include "Arduino.h"

class UserInput{
	public:
	//constructor
	UserInput();
	
    //public functions
	String getSerial();
	
	private:
	//private variables
	char serialChars[20]; //limit serial input to only 20 characters at a time to prevent buffer overflow. Will come later in cpp.
	boolean looper;
	int buffer;
	String data;
};

#endif

source file:

#include "UserInput.h"
#include "Arduino.h"

//constructor
UserInput::UserInput(){
}

//get user input function named getSerial
String UserInput::String getSerial(){
  looper = true;
  buffer = 0;
  data = "";
  while (looper == true)
  {
    if (Serial.available () > 0) //insert later a method to make sure the buffer is not flooded with text.
    {
      delay(50);        
      buffer = Serial.available(); 
      //Serial.println(buffer_size);      
      serialChars[buffer]; 
       for (int x = 0; x < buffer; x++)
       {
         serialChars[x] = Serial.read();
         delay(50);
         data += serialChars[x];
       }
       //Serial.println(serial_data);
       looper = false;
       Serial.flush();
       delay(100);
    }
  }
  return data;
}

sketch:

#include <UserInput.h>

UserInput userinput;

void setup()
{
}

void loop()
{
  //userinput.getSerial();
}

I tried to figure out this error but was not able to.
Thanks for the help on this. I appreciate it.

Wait, I think I see my initialization issue.
Don't post answers yet, I'll post if I came rite or not.

Did not come rite.

Anyone welcome to help now.

So I changed my code to the following:

header file:

#ifndef UserInput_h
#define UserInput_h
#include "Arduino.h"

class UserInput{
	public:
	//constructor used to start an instance of serial communications at baud rate supplied by programmer.
	UserInput(int);
	//public variables
	String data;
    //public functions
	String getSerial();
	
	private:
	//private variables
	char serialChars[20]; //limit serial input to only 20 characters at a time to prevent buffer overflow. Will come later in cpp.
	boolean looper;
	int buffer;
};

#endif

Source File:

#include "UserInput.h"
#include "Arduino.h"

//constructor
UserInput::UserInput(int baud_rate){
 Serial.begin(baud_rate);
}

//get user input function named getSerial
String UserInput::String getSerial(){
  looper = true;
  buffer = 0;
  data = "";
  while (looper == true)
  {
    if (Serial.available () > 0) //insert later a method to make sure the buffer is not flooded with text.
    {
      delay(50);        
      buffer = Serial.available(); 
      //Serial.println(buffer_size);      
      //serialChars[buffer]; 
       for (int x = 0; x < buffer; x++)
       {
         serialChars[x] = Serial.read();
         delay(50);
         data += serialChars[x];
       }
       //Serial.println(serial_data);
       looper = false;
       Serial.flush();
       delay(100);
    }
  }
  return data;
}

Sketch:

#include <UserInput.h>

UserInput userinput(9600);

void setup()
{
  //Serial.begin(9600);
}

void loop()
{
  //userinput.getSerial();
}
String UserInput::String getSerial(){

Why is String in their twice? The function you are trying to implement is UserInput::getSerial().

Ditch the stupid String class BEFORE you dig yourself too deep a whole.

Thanks I'll remove that.
Any reason why you say I might dig myself a hole?

Any reason why you say I might dig myself a hole?

Because Strings are slow, memory-intensive, and non-value added.

Everything that you can do with a String can be done with a string.

Removed the extra String, it compiles fine now. Thank you for the help.

Oh ok, I understand.
Advice noted.