View Single Post
  #5   Spotlight this post!  
Unread 29-10-2016, 18:54
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,064
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: Syntax for 'virtual void GetDescription'?

Code:
virtual void GetDescription (std::ostringstream &desc) const =0
Piece by piece:

Code:
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.

Code:
void
This is the return type. "void" means the function doesn't return anything.

Code:
GetDescription
This is the function name.

Code:
(std::ostringstream &desc)
The function takes a single argument (with the name "desc") of type "std:: ostringstream &". An ostringsteam is 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 here for more info on the various ways you can pass arguments.

Code:
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).

Code:
=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).
Reply With Quote