View Single Post
  #2   Spotlight this post!  
Unread 27-02-2011, 13:59
demosthenes2k8's Avatar
demosthenes2k8 demosthenes2k8 is offline
Graduated but not gone
AKA: Matt Soucy
FRC #0166 (Chop Shop 166)
Team Role: Mentor
 
Join Date: Jan 2009
Rookie Year: 2007
Location: Merrimack, NH
Posts: 589
demosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to beholddemosthenes2k8 is a splendid one to behold
Send a message via AIM to demosthenes2k8 Send a message via Yahoo to demosthenes2k8
Re: Custom data gathering class crashes user program

Well, you don't post the constructor, so we can't help you with that. However, there are a couple things I noticed:
Code:
// NEVER, EVER call the destructor like 
box->~switchbox()
//It's much better to use:
delete box;

// readports can be simplified: 
bool switchbox::readPorts(int port)//this gets the input values from the program switchbox
{
	return DigitalInput(port).Get();
}

// bin2dec is accessing invalid array boundries:
// You have an array[3], but you access 1 2 3.
// Change those to 0 1 2
// Actually, the entire function can be simplified:
int switchbox::bin2dec(bool bit[3])
{
	return (bit[0] | (bit[1] << 1) | (bit[2] << 2));
}

// The for loop in switchbox::Get() will get four bools, but you're trying to store them in an array of 3.
__________________


GSR Dean's List Finalist 2011

Last edited by demosthenes2k8 : 27-02-2011 at 16:17.
Reply With Quote