Thread: is there some language construct to do this?

  1. #1
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838

    is there some language construct to do this?

    Code:
    struct A
    {
      virtual void func()=0;
      void foo(){ func(); }
    };
    
    struct C
    {
      virtual void func(){ std::cout << "C::func\n";
    };
    
    struct AC : public A,public C
    {
      using C::func;
    };
    
    int main void()
    {
      AC ac;
      ac.foo(); // invokes C::func
    }
    obviously this is not what the using directive does, but is there some means of knitting together the vtables like this?

    i realize i can inherit virtually from a common interface that defines the function, i'm just wondering if there is another means of achieving the same thing.

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    No there isn't. At least not in the present version. I'm not sure about C++0x.

    That is decidedly odd, because you have two functions unrelated except in name, and you want one to override another. It's a very special case. If you have control over C, It would be stylistically better to call c::func() something else.

    What you can do is add a func() to AC that calls the C version of func(). Unfortunately, this is likely to add a level of indirection.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 01-21-2010, 04:40 PM
  2. What language did they make Java in?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 07-03-2005, 04:18 PM
  3. Strange loop
    By D@rk_force in forum C++ Programming
    Replies: 22
    Last Post: 12-18-2004, 02:40 PM
  4. assembly language...the best tool for game programming?
    By silk.odyssey in forum Game Programming
    Replies: 50
    Last Post: 06-22-2004, 01:11 PM
  5. Language of choice after C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 47
    Last Post: 06-15-2004, 01:20 AM