Go to Post "FIRST isn't what it used to be anymore. It makes me upset and it makes me question many things." - Arefin Bari [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 29-10-2016, 16:43
RyZeRun RyZeRun is offline
Registered User
FRC #4104
 
Join Date: Oct 2016
Location: Spokane, WA
Posts: 4
RyZeRun is an unknown quantity at this point
Question Syntax for 'virtual void GetDescription'?


The WPILib documentation won't explain it well enough for me. It says:

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

I have no idea what the 'std:stringstream &desc' and 'const =0' parts mean. Can someone explain?
Reply With Quote
  #2   Spotlight this post!  
Unread 29-10-2016, 16:46
RyZeRun RyZeRun is offline
Registered User
FRC #4104
 
Join Date: Oct 2016
Location: Spokane, WA
Posts: 4
RyZeRun is an unknown quantity at this point
Re: Syntax for 'virtual void GetDescription'?

Some of my post was accidentally converted to an Emoji.
I MEANT 'std::ostringstream &desc'
Reply With Quote
  #3   Spotlight this post!  
Unread 29-10-2016, 18:08
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 305
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Syntax for 'virtual void GetDescription'?

Which class is this method from?
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
Reply With Quote
  #4   Spotlight this post!  
Unread 29-10-2016, 18:13
AustinSchuh AustinSchuh is offline
Registered User
FRC #0971 (Spartan Robotics) #254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Feb 2005
Rookie Year: 1999
Location: Los Altos, CA
Posts: 800
AustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond reputeAustinSchuh has a reputation beyond repute
Re: Syntax for 'virtual void GetDescription'?

Quote:
Originally Posted by RyZeRun View Post
Some of my post was accidentally converted to an Emoji.
I MEANT 'std:stringstream &desc'
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.
Reply With Quote
  #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,071
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
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 02:59.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi