Syntax for 'virtual void GetDescription'?

::rtm:: :ahh: :mad:
The WPILib documentation won’t explain it well enough for me. It says:

virtual void GetDescription (std::ostringstream &desc) const =0

I have no idea what the ‘std::ostringstream &desc’ and ‘const =0’ parts mean. Can someone explain?

Some of my post was accidentally converted to an Emoji.
I MEANT ‘std::ostringstream &desc’

Which class is this method from?

What are you trying to do? Can you share the code that triggered this error?

GetDescription takes a reference to an ostringstream.

const = 0 means that the method is pure virtual (ie, it must be implemented in subclasses). So, you are trying to do something with an interface, not the implementation.


virtual void GetDescription (std::ostringstream &desc) const =0

Piece by piece:

virtual

This means that the function is virtual. Derived classes can provide a function with the same signature that will be called instead even if you call the function through a reference or pointer to the base class. Read more here.

void

This is the return type. “void” means the function doesn’t return anything.

GetDescription

This is the function name.

(std::ostringstream &desc)

The function takes a single argument (with the name “desc”) of type “std:: ostringstream &”. An ostringsteamis an output stream that operates on strings. String streams are useful for building strings piece-by-piece (normal C++ strings are immutable, so if you build a string by concatenating smaller strings together, you do a lot of object creation and deletion, which is inefficient). The “&” means that the parameter is passed by reference. See herefor more info on the various ways you can pass arguments.

const

This means that the function is not allowed to change any internal class members (if you try, you’ll get a compile error unless you use a const_cast to override this).

=0

This part is an addendum onto “virtual”…it further means that this function is “pure virtual”. This means that this class is an abstract and cannot be instantiated. What good is a class that can’t be instantiated? Well, you can have other classes that inherit from this one, and they can supply their own implementation of this method (in fact, they need to, otherwise they are also abstract).