Puzzle: What will be the output of the following program?
struct B {
void foo () {
printf ("B::foo");
}
};
void foo () {
printf("::foo");
}
template <typename Base>
struct Derived : public Base {
void bar () { foo (); }
};
int main (void) {
Derived <B> d;
d.bar();
return 0;
}
Answer: C++ compiler does not perform template argument dependent lookup because the rule is to lookup as many names as possible at the time of parsing the template the first time. It does not wait till the instantiation of it. So ::foo!
struct B {
void foo () {
printf ("B::foo");
}
};
void foo () {
printf("::foo");
}
template <typename Base>
struct Derived : public Base {
void bar () { foo (); }
};
int main (void) {
Derived <B> d;
d.bar();
return 0;
}
Answer: C++ compiler does not perform template argument dependent lookup because the rule is to lookup as many names as possible at the time of parsing the template the first time. It does not wait till the instantiation of it. So ::foo!
Comments
Sexy Lady
Escort London