View Single Post
  #7   Spotlight this post!  
Unread 04-12-2011, 12:36
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Using a variable as a class object in Windriver/C++

Quote:
Originally Posted by Stonemotmot View Post
Say I named a solenoid object 1 and had a int variable named b that stored 1 could i say
b.Set(true) and have the same result as 1.Set(True)
Many people are answering your question, but no one has asked why you want to do this. Generally numbers are a poor way to refer to things. Especially if the numbers are arbitrary (don't have any meaning in the mechanism you are controlling).

The best generic way to do this is to simply name variables or pointers for each mechanism and use those to refer to the solenoids or anything else.

Such as:

Code:
Solenoid *leftGripper = new Solenoid(2);
Solenoid *impaler = new Solenoid(3);

impaler->Set(true);
or

Code:
class MyRobot : public IterativeRobot
{
...
Solenoid leftGripper;
Solenoid impaler;
...
	MyRobot() :
		leftGripper(2),
		impaler(3)
	{
	}
...
	void AutonomousInit(void)
	{
		impaler.Set(true);
	}
...
};

Do you have some compelling reason not to refer to each object directly?