Aug 10, 2014 at 12:54pm
according to me the output of the following program should be 2 and 4 but its not,y?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include<iostream>
using namespace std;
class Bix
{
int x, y;
public:
void show(void);
void main(void);
};
void Bix::show(void)
{
Bix b;
b.x = 2;
b.y = 4;
cout<< x << " " << y;
}
void Bix::main(void)
{
Bix b;
b.x = 6;
b.y = 8;
b.show();
}
int main()
{
Bix run;
run.main();
return 0;
}
|
Last edited on Aug 11, 2014 at 8:04pm
Aug 10, 2014 at 1:04pm
Line 16 is printing out x and y of the object the show function was called on, not the b object that is created new in show.
Changing line 16 to cout<< b.x << " " << b.y;
would give the result you think you should be getting (I assume you mean 2 and 4 instead of 2 and 3?).