using-directive question

From: David Crocker (dcrocker_at_eschertech.ccoomm)
Date: 03/31/04


Date: Wed, 31 Mar 2004 15:37:16 +0100

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. But will the call to
f() within g() bind statically to A :: f() (as it would if I explicitly said
"return A :: f()" instead if using the using-directive), or dynamically A ::
f() or whatever override it? In other words, should the call "foo()" return
0 or 1? I am looking for dynamic binding to occur, but I don't find the C++
Standard clear on this point.

-- 
David Crocker
Escher Technologies
www.eschertech.com


Relevant Pages

  • Re: Funky function
    ... >> It makes it possible to call this member function on a const object ... >> object may or may not be const). ... int Data; ... in the next line you try to call a function foo on MyData. ...
    (comp.lang.cpp)
  • Re: Difficulty with nested template classes (newbie)
    ... the huge post but I am including first the errors, then the template ... Reference initialized with 'const double', ... matrix& lookup (int row, int col); ... // iterator operator++ ...
    (comp.lang.cpp)
  • Re: accessor member functions and const
    ... > reference the returned value v. ... int& val ... const int& valconst ... so one cannot modify the object via the reference. ...
    (alt.comp.lang.learn.c-cpp)
  • [2.6.6-BK] NTFS 2.1.11 Really final cleanups.
    ... throughout the NTFS code to ntfschar since uchar_t is already defined by POSIX ... +BOOL find_attr(const ATTR_TYPES type, const ntfschar *name, const u32 name_len, ... register int rc; ...
    (Linux-Kernel)
  • Re: On-the-fly Le Chatelier
    ... LeChatelier(int P, int V, int T, int N) ... void setP(int P) ... change(const change& c) ... > virtual int GetA() const ...
    (comp.lang.cpp)