Go to Post I'm excited. Probably too much, but eh, I'm a big geek. - Brandon Martus [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Spotlight this post!  
Unread 01-05-2013, 21:20
davidthefat davidthefat is offline
Alumni
AKA: David Yoon
FRC #0589 (Falkons)
Team Role: Alumni
 
Join Date: Jan 2011
Rookie Year: 2010
Location: California
Posts: 792
davidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud ofdavidthefat has much to be proud of
Re: [Q] I need help with passing an array of pointers to an object

First of all, you can make
Code:
for (int x = 0; x < 10; x++) {
		buttons[x] = false;
	}
into this:

Code:
buttons = {0}; //This fills the array with 0's, which is equivalent to false.
Secondly, I am partial against using the "<=" operator in a for loop; I suggest just sticking with "<".

*victor points to the pointer to a pointer to an array of pointers to Victor objects. Now, what many C/C++ novices overlook is the fact that the array and pointer notations are interchangeable. So, let's see this example:

Code:
int foo[10] = {0};
for(int i = 0; i < 10; i++)
  foo[i] = i;
//Is the same as this:
for(int i = 0; i < 10; i++)
  *(foo+i) = i;
So, that being said, look at how you declared your Victor array. I don't think you are doing what you are trying to do.

I would do:
Code:
Victor **victors;
//All the other stuff...

JoystickInput::JoystickInput(Joystick * joy, Victor **vicArray) {
	joystick = joy;
	buttons = {0};
	victors = vicArray;
	}

//Then when you declare that array that you pass in:

Victor *drivers = new Victor[8];

//Fill the array like drivers[0] = new Victor();
//Then pass it into the function.

JoystickInput(joy, &drivers);
Hopefully that helps. I might have made a simple mistake here or there, but keep in mind that I've been almost exclusively been programming in C this year.

Last edited by davidthefat : 01-05-2013 at 21:33.
Reply With Quote
 


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 06:09.

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