Go to Post The minibot horse is dead. Stop trying to beat it. Glue is too cheap. - Taylor [more]
Home
Go Back   Chief Delphi > Technical > Programming
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 28-06-2016, 19:36
CB313 CB313 is offline
Registered User
FRC #0313
 
Join Date: Jun 2016
Location: Westland, Michigan
Posts: 4
CB313 is an unknown quantity at this point
C++ NetworkTable code error

I'm getting an error in my code
Code:
cannot convert 'std::shared_ptr<NetworkTable>' to 'NetworkTable*' in assignment
Can someone help me explain what this means? I'm rather new to coding, and I don't understand what i did wrong. I copied the code from the FRC Network Tables page (Here) And the line
Code:
	table = NetworkTable::GetTable("datatable");
is the only one with an error. If it's any help, the whole code is here.
Reply With Quote
  #2   Spotlight this post!  
Unread 28-06-2016, 21:25
axton900's Avatar
axton900 axton900 is online now
Programming Co-Captain
FRC #1403 (Cougar Robotics)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2015
Location: New Jersey USA
Posts: 45
axton900 has a spectacular aura aboutaxton900 has a spectacular aura aboutaxton900 has a spectacular aura about
Re: C++ NetworkTable code error

Hey!
The getTable method returns a shared pointer. So you have to declare your table as a shared pointer by writing:
std::shared_ptr<NetworkTable> table = NetworkTable::GetTable("datatable");

That should fix that issue!


That tutorial is from 2014 and WPILib has been updated and is now in C++11 which introduced Smart Pointers. I would suggest taking a look at the library :Here!
__________________
Team 1403: Cougar Robotics (2015 - present)

Reply With Quote
  #3   Spotlight this post!  
Unread 28-06-2016, 23:17
alst alst is offline
Programming Mentor
AKA: Alan
FRC #0830 (RatPack)
Team Role: Mentor
 
Join Date: Jul 2015
Rookie Year: 1830
Location: MI
Posts: 10
alst is an unknown quantity at this point
Re: C++ NetworkTable code error

(That link should be this instead - missing a colon.)

Basically, the error means that the type of your table variable is "NetworkTable*" (a pointer to a NetworkTable), while GetTable() returns a std::shared_ptr<NetworkTable>, which can't be converted to a NetworkTable* directly. The place you actually want to change is currently line 9 in your code, where you declare "table" - it should be "std::shared_ptr<NetworkTable> table;".
Reply With Quote
  #4   Spotlight this post!  
Unread 28-06-2016, 23:32
Thad House Thad House is offline
Volunteer, WPILib Contributor
no team (Waiting for 2021)
Team Role: Mentor
 
Join Date: Feb 2011
Rookie Year: 2010
Location: Thousand Oaks, California
Posts: 1,076
Thad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond reputeThad House has a reputation beyond repute
Re: C++ NetworkTable code error

The things posted above are the proper solution. I'll contact the Screensteps people to get it updated.
__________________
All statements made are my own and not the feelings of any of my affiliated teams.
Teams 1510 and 2898 - Student 2010-2012
Team 4488 - Mentor 2013-2016
Co-developer of RobotDotNet, a .NET port of the WPILib.
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 10:15.

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