 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
David Crocker Guest
|
Posted: Thu Apr 01, 2004 6:14 pm Post subject: using-directives and dynamic binding |
|
|
I have a question about using-directives. Consider the following:
class A {
public:
virtual int f() const { return 0;}
}
class B : public A {
public:
int f(int x) const { return x; } // hides the inherited f()
using A :: f; // un-hides the inherited f()
int g() const { return f(); }
}
class C : public B {
public:
int f() const { return 1; }
}
int foo() {
B* temp = new C;
return temp->g();
}
The declaration of g() in class B relies on the directive "using A :: f;" to
make the declaration of f() inherited from A visible. This is described in
section 10.2 para 2 of ISO/IEC 14882:1998(E). But will the call to f()
within g() bind statically to A :: f() (as it would if I explicitly said
"return A :: f()" instead of using the using-directive); or dynamically to A
:: f() or C :: f() depending on the type of the 'this' pointer at run-time?
In other words, should the call "foo()" return 0 or 1?
I don't find the Standard clear on this point. Section 10.2 ("Member name
lookup") is silent on whether a call to a declaration that has been made
visible by a using-directive is statically or dynamically bound. Section
10.3 ("Virtual functions") is silent on whether a using-directive affects
whether binding is static or dynamic in the way that explicit scope
resolution does.
--
David Crocker
Escher Technologies
www.eschertech.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|