V
Vijai Kalyan
A very simple question. I have never had occasion to think about this
before.
Consider the following:
class A
{
virtual unsigned long bar()
{
return reinterpret_cast<unsigned long> (this);
}
};
class B
{
};
void foo()
{
B* b = new B;
A* a = b;
std::cout << "b == a?" << std::boolalpha << (a == b) << std::endl;
}
I would have thought this would print
true
but it doesn't. Does this mean that "a" only points at the "A" part of
"b"?
But, of course, if I do "a->bar()" the correct function from "B" will
be invoked. This is due to the fact that bar is a virtual function
which means the compiler does the correct thing.
Can someone tell me then why the pointers are different?
thanks,
-vijai.
before.
Consider the following:
class A
{
virtual unsigned long bar()
{
return reinterpret_cast<unsigned long> (this);
}
};
class B
{
};
void foo()
{
B* b = new B;
A* a = b;
std::cout << "b == a?" << std::boolalpha << (a == b) << std::endl;
}
I would have thought this would print
true
but it doesn't. Does this mean that "a" only points at the "A" part of
"b"?
But, of course, if I do "a->bar()" the correct function from "B" will
be invoked. This is due to the fact that bar is a virtual function
which means the compiler does the correct thing.
Can someone tell me then why the pointers are different?
thanks,
-vijai.