#include <iostream>
class A
{
public:
virtualvoid foo()
{
std::cout << "A";
}
};
class B: public A
{
public:
virtualvoid foo()
{
std::cout << "B";
}
};
int main()
{
B x;
A& y = x;
B z = dynamic_cast<B&>(y);
x.foo();
y.foo();
z.foo();
}
Yes, I read the content on the first link, but still have some doubts.
About MiiNiPaa's answer:
Which is the difference between A& y = x;
and A* y = &x;
?
I mean, if I'm not wrong A* means a pointer, so y would be a point to x in second statement.
What is y in first statement then? The same?