Go to Post Our strong support is the result of 14 years of very organized "nagging". :) - OZ_341 [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #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?
 


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 23:37.

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