A
Arindam
#include <cstdio>
struct Test {
void bar() {
foo();
}
private:
virtual void foo() {
printf("Test\n");
}
};
struct Test2 : public Test {
void foo() {
printf("Test2\n");
}
};
int main(int argc, char* argv[])
{
Test2 v;
v.bar();
}
Does the call to v.bar() amount to a polymorphic invocation of foo()?
If not, I am guessing the following will be polymorphic:
int main(int argc, char* argv[])
{
Test2 v;
Test * pv = &v;
pv->bar();
}
bar takes a _this_ pointer whose static type is Test*. Therefore I am
reasoning that v.bar is something like:
bar(Test* this) being invoked as:
Test2 v;
bar(&v);
But inside bar, the static type of _this_ is really Test*. But
invoking foo() on it will resolve to Test2::foo. So both should be
polymorphic. Ami I correct?
Cheers,
Arindam
struct Test {
void bar() {
foo();
}
private:
virtual void foo() {
printf("Test\n");
}
};
struct Test2 : public Test {
void foo() {
printf("Test2\n");
}
};
int main(int argc, char* argv[])
{
Test2 v;
v.bar();
}
Does the call to v.bar() amount to a polymorphic invocation of foo()?
If not, I am guessing the following will be polymorphic:
int main(int argc, char* argv[])
{
Test2 v;
Test * pv = &v;
pv->bar();
}
bar takes a _this_ pointer whose static type is Test*. Therefore I am
reasoning that v.bar is something like:
bar(Test* this) being invoked as:
Test2 v;
bar(&v);
But inside bar, the static type of _this_ is really Test*. But
invoking foo() on it will resolve to Test2::foo. So both should be
polymorphic. Ami I correct?
Cheers,
Arindam