V
Vinodh Kumar
#include <iostream>
using namespace std;
struct A
{
virtual void fa();
};
struct B : public A
{
virtual void fa();
};
void A::fa()
{
cout << "A::fa" << endl;
}
void B::fa ()
{
cout << "B::fa" << endl;
}
int main()
{
/*
// 1. Normal objects
A a;
B b;
a = b;
(&a)->fa();
// 2. Pointers
A a;
B b;
A* a1 = &b;
a1->fa();
*/
//3. References
A a;
B b;
A& a1 = b;
a1.fa();
return 0;
}
In the above program within main( ) inside the commented block // 1. Normal
objects,
a = b;
(&a)->fa();
does not make an invocation to B::fa();Why is that?Then what the above
assignment does in the same block.Shed some light please.
Regards,
Vinodh Kumar P
using namespace std;
struct A
{
virtual void fa();
};
struct B : public A
{
virtual void fa();
};
void A::fa()
{
cout << "A::fa" << endl;
}
void B::fa ()
{
cout << "B::fa" << endl;
}
int main()
{
/*
// 1. Normal objects
A a;
B b;
a = b;
(&a)->fa();
// 2. Pointers
A a;
B b;
A* a1 = &b;
a1->fa();
*/
//3. References
A a;
B b;
A& a1 = b;
a1.fa();
return 0;
}
In the above program within main( ) inside the commented block // 1. Normal
objects,
a = b;
(&a)->fa();
does not make an invocation to B::fa();Why is that?Then what the above
assignment does in the same block.Shed some light please.
Regards,
Vinodh Kumar P