This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

c++/3007: impossibility to discard "virtual" and/or to get to know, for which class(not instance) the method, currently being executed, has been called



>Number:         3007
>Category:       c++
>Synopsis:       impossibility to discard "virtual" and/or to get to know, for which class(not instance) the method, currently being executed, has been called
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed May 30 14:16:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     V. Kaufman
>Release:        gcc version 2.95.2 19991024 (release)
>Organization:
>Environment:
i486-suse-linux
>Description:
In C++ programs with a long class hierarchy with
nested calls of (to the best advantage)virtual methods
it is sometimes useful to be able to "discard" "virtual".

In particular, consider the following simplified example:
#include <iostream.h>

class F1{
public:
  virtual void f() { cout << "in F1" << endl; }
  virtual void build_using_f(){
    f(); 
    //...lots of code follow
  }
  void play_using_f(){
    build_using_f(); //...
  }
};
class F2 : public F1{
  void f() { cout << "in F2" << endl; }
  void play_using_f(){ cout << "game over" << endl; }
};

Now, if you want (for some weighty reasons)(probably
you want to use your mighty class F1 features for a
F2 child-instance, which is the sense of "object oriented")
to call play_using_f() for a F2 class instance as if that
instance were F1 (and one part of it is actually), you would
tend to write:
  F2 my_f2; my_f2.F1::play_using_f();
But this uses F2::f() and not F1::f().

I miss some directive like:
  (TREAT_AS_F1 my_f2).play_using_f();

I also miss smth. like:

  void build_using_f(){
    CLASS_FOR_WHICH_THIS_METHOD_WAS_CALLED::f();
    //Note, "class" here is not equal "instance" type, since
    //I could have called SOME_CLASS::build_using_f(); explicitely
  }
>How-To-Repeat:

>Fix:
In my program I added another "build_using_f" (see the
description example above), that can take "f()" as
argument.
The disadvantage was: performance decreased considerably
("f()" was called frequently).
Introducing new methods (doing 99% the same)
would be ugly.
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]