Hi, I'm having a bit of trouble with a class I wrote, it appears to be crashing the user program as soon a VxWorks attempts to launch it. I'm not sure what part of it is crashing it either, but i have tried commenting out everything in its Get(); member so the only thing left was a return 0; statement to see if that was the problem, so I'm assuming its the constructor.
The way the code is meant to work is gather bits from three dip switches, and then translate that binary sequence into a more usable decimal number.
this is how I have been calling the constructor and destructor. I have tried not using an object pointer, but i still had the same problem.
Code:
switchbox *box = new switchbox(10, 9, 8);
int mode2= box->Get();
box->~switchbox();
and this is the class:
Code:
class switchbox {
public:
int Get();
switchbox(int port1, int port2, int port3);
virtual ~switchbox();
private:
bool port1;
bool port2;
bool port3;
int mode;
int bin2dec(bool bit[3]);
bool readPorts(int port);
};
bool switchbox::readPorts(int port)//this gets the input values from the program switchbox
{
DigitalInput *digital = new DigitalInput(port);
bool port_ = false;
port_ = digital->Get();
digital->~DigitalInput();
return port_;
}
int switchbox::bin2dec(bool bit[3])//this is a 3 bit binary to decimal converter.
{ //to be used for the program switchbox.
int num=0;
if (bit[1]) {
num=num+1;
}
if (bit[2]){
num=num+2;
}
if (bit[3]) {
num=num+4;
}
return mode = num; //member functions can access private data, doing this to hopefully not need another int.
}
int switchbox::Get(){
bool bit[3];
for( int i=0; i<=3; i++){
bit[i] = switchbox::readPorts(i);
}
bin2dec(bit);
return mode;
}
thanks to anyone who can help with this!