TinyGPS++ gps object creation and SoftwareSerial start problems

I have created a class that represents a NE0-6M GPS Module but if I create the TinyGPSPlus gps object and begin the SoftwareSerial in the constructor, I can not use it in any future functions

The class code:

#include <TinyGPS++.h>
#include <SoftwareSerial.h>


class NEO_6Mgps
{
    private:
    //  byte pinRX, pinTX;
      static const uint16_t GPSBaud = 9600;


    
    public:
      NEO_6Mgps(byte aPinRX,byte aPinTX)
      {
        // The TinyGPS++ object
        TinyGPSPlus gps;
        
        // The serial connection to the GPS device
        SoftwareSerial ss(aPinRX, aPinTX);

        ss.begin(GPSBaud);
      }

      
      void GPSlocation()
      {   
        if (ss.available() > 0)
        {
          gps.encode(ss.read());
          
          if (gps.location.isUpdated())
          {
            Serial.print("Latitude= "); 
            Serial.print(gps.location.lat(), 6);  // 6 = no of digits
            
            Serial.print(" Longitude= "); 
            Serial.println(gps.location.lng(), 6);

          } 

          
          Serial.print("Speed in m/s = ");
          Serial.println(gps.speed.mps()); 
        }
      }
    
};

Error:

exit status 1
'ss' was not declared in this scope

I have tried using a new function Start() -that contains the TinyGPSPlus object and SoftwareSerial.begin- which is called at the start of void GPSlocation() only once, but the same problem persists.

How can I resolve this without creating a new object every time GPSlocation() is called?

You can't instantiate a class within one function of a class definition and then reference it in a different function of the class definition unless you have save that instantiation as a class global to the one you're writing.

I'd suggest using a "Stream" object that you can use as a placeholder for a Serial/SoftwareSerial class. With this "Stream" object, you can utilize everything a normal Serial or SoftwareSerial class can (with the exception of begin()).

Here is an example of how to use a "Stream" object within a class (this is a library): Example library (look at the .h and the .cpp files)

Power_Broker:
You can't instantiate a class within one function of a class definition and then reference it in a different function of the class definition unless you have save that instantiation as a class global to the one you're writing.

Nonsense and gibberish. OP is just doing it wrong. He / She needs to make the SoftwareSerial object private to the class, not local to the constructor. Then, use an Initializer List. Then, provide a 'begin()' method for the class:

#include <SoftwareSerial.h>

class MyClass {
  private:
    SoftwareSerial ss;

  public:
    MyClass(byte aPinRX, byte aPinTX) : ss(aPinRX, aPinTX) {
    }

    void begin() {
      ss.begin(9600);
    }

    void sayHello() {
      ss.println("Hello World");
    }
};

MyClass myObject(3,4);

void setup() {
  myObject.begin();
  myObject.sayHello();
}

void loop() {
}

gfvalvo:
He / She needs to make the SoftwareSerial object private to the class, not local to the constructor.

That's literally what I said, just easier to read, lol. You can also make the object public...

I still say it's more robust to use a Stream object instead.