S
sven.bauer
Hi,
I have a question following up the following slightly older posting:
http://groups.google.de/group/comp.lang.c++/browse_thread/thread/40e52371e89806ae/52a3a6551f84d38b
class Base
{
virtual Base& operator = (const Base &k) {}
};
class Derived: public Base
{
virtual Base& operator = (const Base &k) {}
};
int main(int argc, char* argv[])
{
Derived *dp1 = new Derived();
Derived *dp2 = new Derived();
*dp1 = *dp2; // Base:perator= is called
Base *bp = *dp1;
*bp = *dp2; // Derived:perator= is called
return 0;
}
While it seems clear to me why *bp = *dp2 leads to the
Derived:perator= being called I do not understand why *dp1 = *dp2
calls the Base:perator=.
What's going on here???
Thanks!
Sven
I have a question following up the following slightly older posting:
http://groups.google.de/group/comp.lang.c++/browse_thread/thread/40e52371e89806ae/52a3a6551f84d38b
class Base
{
virtual Base& operator = (const Base &k) {}
};
class Derived: public Base
{
virtual Base& operator = (const Base &k) {}
};
int main(int argc, char* argv[])
{
Derived *dp1 = new Derived();
Derived *dp2 = new Derived();
*dp1 = *dp2; // Base:perator= is called
Base *bp = *dp1;
*bp = *dp2; // Derived:perator= is called
return 0;
}
While it seems clear to me why *bp = *dp2 leads to the
Derived:perator= being called I do not understand why *dp1 = *dp2
calls the Base:perator=.
What's going on here???
Thanks!
Sven