Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   C++ NetworkTable code error (http://www.chiefdelphi.com/forums/showthread.php?t=149222)

CB313 28-06-2016 19:36

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.

axton900 28-06-2016 21:25

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!

alst 28-06-2016 23:17

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;".

Thad House 28-06-2016 23:32

Re: C++ NetworkTable code error
 
The things posted above are the proper solution. I'll contact the Screensteps people to get it updated.


All times are GMT -5. The time now is 10:15.

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