T
Tahir Hashmi
Consider this piece of code:
#include <iostream>
using namespace std;
class y
{
public:
void draw()
{
cout << "Drawing Y" << endl;
}
void Yguy()
{
cout << "Y Guy Called" << endl;
}
};
int main()
{
int x1;
y* yPtr = (y*) &x1;
yPtr->draw();
yPtr->Yguy();
}
I was expecting a runtime error in the calls to draw() and Yguy() but
it doesn't happen! I tried it with VC++ .Net and GCC 3.2.2 and both
gave the output:
Drawing Y
Y Guy Called
Any explanations?
#include <iostream>
using namespace std;
class y
{
public:
void draw()
{
cout << "Drawing Y" << endl;
}
void Yguy()
{
cout << "Y Guy Called" << endl;
}
};
int main()
{
int x1;
y* yPtr = (y*) &x1;
yPtr->draw();
yPtr->Yguy();
}
I was expecting a runtime error in the calls to draw() and Yguy() but
it doesn't happen! I tried it with VC++ .Net and GCC 3.2.2 and both
gave the output:
Drawing Y
Y Guy Called
Any explanations?