This is code that is giving me trouble:
The output from this code should be:Code:int main(void) { const char Off[] = "Off"; Sensor *X = new Sensor("On", "near the front door"); MainFrame *W = new MainFrame("Off"); cout << "Sensor X is located " << X->GetLocation() << endl; cout << "Sensor X is currently " << X->GetSensorState() << endl;
Sensor X is located near the front door (this works)
Sensor X is currently On
Instead I get:
Sensor X is located near the front door
Sensor X is currently Onnear the front door
This is the function GetSensorState:
All it does is return State which is a protected character array. State is defined asCode:inline char *GetSensorState() { return State; }
char State[2] (only meant to hold 'On' or 'Off' so i figured 2 is enough)
The function GetLocation is:
All GetLocation does is return itsLocation which is a protected character array that describes the location of the sensorCode:inline char *GetLocation() { return itsLocation; }
itsLocation is defined as:
char itsLocation[50];
I am honestly not sure what is wrong here, this is quite strange.



LinkBack URL
About LinkBacks


