Returning the "Serial" object as an instance of Stream

Hi guys!

I'm building a library that will allow you to debug your code faster. It is all based arround the Serial object. What i want to do is to have a function that returns to the user the Serial object. I know for a fact that Serial is an instance of Stream class. So, i tryed simply making a function like this:

Stream Debug::getBaseObject(){
    return Serial;
}

This is being defined above using something like this:

class Debug{
    public:
        ....
        Stream getBaseObject();

    private:

};

Using this i get an error, something that goes like this: "error: invalid abstract return type for member function 'Stream Debug::getBaseObject()".

I searched for a bit for other library that has a function that returns a Stream... but had no luck there :frowning:

Any ideas would be apreciated! Thanks!

I know for a fact that Serial is an instance of Stream class. So, i tryed simply making a function like this:

You'd be wrong, then. Serial is an instance of HardwareSerial, which derives from Stream.

You can return instances of the concrete HardwareSerial class, but not the abstract Stream class.

But, really, why do you need to do this? The sketch should have told your class which output Stream object to use. So, it already KNOWS what you are trying to return.

ciolouise222:
Using this i get an error, something that goes like this: "error: invalid abstract return type for member function 'Stream Debug::getBaseObject()".

I searched for a bit for other library that has a function that returns a Stream... but had no luck there :frowning:

Any ideas would be apreciated! Thanks!

Make the return type a reference.