Go to Post You can learn just as much from building a small robot as you can from a large bot because all of the key concepts are the same. - Greg Needel [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 Rating: Thread Rating: 4 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 09-12-2010, 01:42
ehlochbr ehlochbr is offline
Registered User
FRC #2990
 
Join Date: Nov 2010
Location: Salem, OR
Posts: 37
ehlochbr is an unknown quantity at this point
Error: within this context

I'm trying to add the code for the Axis camera and I keep seeing this error when I build the project "error: within this context".

#include "WPILib.h"
#include "Gamepad.h"
#include "Vision/AxisCamera.h"

class RobotDemo : public SimpleRobot
{
RobotDrive myRobot; // robot drive system
Gamepad controller;
AxisCamera camera;

public:
RobotDemo(void):
myRobot(10, 9, 2, 1), // these must be initialized in the same order
controller(1)
{ <------ERROR HERE

All I did was add the AxisCamera header file and the identifier (AxisCamera camera).

What am I missing? Thanks.
Reply With Quote
  #2   Spotlight this post!  
Unread 09-12-2010, 03:16
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,752
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Error: within this context

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.

Gotta love compiler error messages sometimes.

Greg McKaskle
Reply With Quote
  #3   Spotlight this post!  
Unread 09-12-2010, 09:01
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Error: within this context

AxisCamera is a singleton. You shouldn't be calling the constructor directly. Try this.
Code:
AxisCamera& camera;

//In your constructor do this
camera = AxisCamera::GetInstance();

Last edited by Dave Scheck : 09-12-2010 at 10:13. Reason: Changed my pointer to a reference to match the prototype
Reply With Quote
  #4   Spotlight this post!  
Unread 09-12-2010, 09:59
ehlochbr ehlochbr is offline
Registered User
FRC #2990
 
Join Date: Nov 2010
Location: Salem, OR
Posts: 37
ehlochbr is an unknown quantity at this point
Re: Error: within this context

Thanks for the reply. It looks like I have a different problem now. When I try to implement your suggestion and use:

Code:
camera = AxisCamera::GetInstance();
I get an error that says "cannot convert 'AxisCamera' to 'AxisCamera*' in assignment". Can you explain what this means?

Thanks again.
Reply With Quote
  #5   Spotlight this post!  
Unread 09-12-2010, 10:09
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Error: within this context

You should declare the camera as:
Code:
AxisCamera &camera;

camera = AxisCamera::GetInstance();
__________________
Reply With Quote
  #6   Spotlight this post!  
Unread 09-12-2010, 10:15
Dave Scheck's Avatar
Dave Scheck Dave Scheck is offline
Registered User
FRC #0111 (WildStang)
Team Role: Engineer
 
Join Date: Feb 2003
Rookie Year: 2002
Location: Arlington Heights, IL
Posts: 574
Dave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond reputeDave Scheck has a reputation beyond repute
Re: Error: within this context

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.
Reply With Quote
  #7   Spotlight this post!  
Unread 09-12-2010, 17:54
ehlochbr ehlochbr is offline
Registered User
FRC #2990
 
Join Date: Nov 2010
Location: Salem, OR
Posts: 37
ehlochbr is an unknown quantity at this point
Re: Error: within this context

I really appreciate both of your replies, but making the corrections you suggested has led me to another problem.

Code:
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.
Reply With Quote
  #8   Spotlight this post!  
Unread 09-12-2010, 18:01
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: Error: within this context

Quote:
Originally Posted by ehlochbr View Post
I really appreciate both of your replies, but making the corrections you suggested has led me to another problem.

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:
Code:
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::ZomBDashboardPacketSen der()':
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
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib

Last edited by byteit101 : 09-12-2010 at 18:08. Reason: expanding
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
What's this number 80 in error math? K.Porter Programming 3 25-01-2007 18:28
Glitches Eliminated using Interrupt Context Saving, BUT ... mluckham Programming 22 09-01-2007 17:19
Trying to follow C18 interrupt context code... dcbrown Programming 5 21-12-2006 09:01
What is this error message? chantilly_team Programming 3 22-01-2005 10:09
Explain this link error? Larry Barello Programming 1 16-01-2004 11:06


All times are GMT -5. The time now is 14:58.

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