You’ve added a data member called camera, of type AxisCamera, no problem there. But the code you’ve included has a constructor with an initialization list, and you haven’t added a value for camera field.
Not being that familiar with the C++ WPI code, the issue is likely that the AxisCamera doesn’t have a default constructor or for some other reason, the compiler wants camera to be assigned using the initialization list.
Try putting
camera(???)
after the controller(1) line and before the {. Replace ??? with the parameters required for an AxisCamera object to be initialized.
Thanks for the correction mikets. I misread the header when I wrote my initial post. I updated it to have the reference declaration instead of a pointer.
I really appreciate both of your replies, but making the corrections you suggested has led me to another problem.
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Gamepad controller;
AxisCamera& camera;
public:
RobotDemo(void):
myRobot(10, 9, 2, 1),
controller(1)
{ <-------------------------ERROR HERE
GetWatchdog().SetExpiration(0.1);
camera = AxisCamera::GetInstance(); <--------ERROR HERE
The first error says “uninitialized reference”. How do I initialize it?
The second error gets me back to where I started. It says “error within this context”.
This feels like one step forward then two steps back. Thanks for your help.
You need to initialize all non pointer members before the body (and especially references, they only have one life)
try this:
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Gamepad controller;
AxisCamera& camera;
public:
RobotDemo(void):
myRobot(10, 9, 2, 1),
controller(1),
camera(AxisCamera::GetInstance())
{
GetWatchdog().SetExpiration(0.1);
Also, “error within this context” is part of a larger error, open the build console and find the red lines to find the rest of the message. many messages are 2 or more parts.
Ex (bold is error in code)
file.cpp: In constructor ZomBDashboardPacketSender::ZomBDashboardPacketSender()':** file.cpp:301: error: uninitialized reference member ZomBDashboardPacketSender::hp’
**WPILib/Dashboard.h:58: error: `void Dashboard::operator=(const Dashboard&)’ is private file.cpp:302: error: within this context