Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!cs.utexas.edu!milano!cadillac!dsouza From: dsouza@optima.cad.mcc.com (Desmond Dsouza) Newsgroups: comp.lang.c++ Subject: Re: virtual static class functions Message-ID: Date: 18 Mar 90 19:22:00 GMT References: <38579@cornell.UUCP> <10586@alice.UUCP> Sender: news@cadillac.CAD.MCC.COM Organization: MCC CAD Program, Austin, Texas Lines: 77 In-reply-to: ark@alice.UUCP's message of 17 Mar 90 05:31:50 GMT I am re-posting this as I forgot to mark the Distribution last time. In <38579@cornell.UUCP> deb@svax.cs.cornell.edu (David Baraff) writes: ark@alice.UUCP (Andrew Koenig) replies: foo(); Clearly, foo() cannot access any non-static data or function members of Base because of case (a). 2. The above restriction does NOT rule out permitting foo() to be VIRTUAL. If the invocation is as in (a) above, the call is resolved statically, like any other member function call -- virtual or non-virtual. If the invocation is as in (b) above, the call gets resolved dynamically through the virtual function table. Only VIRTUAL static member functions need be entered in this table. Normally, virtual member functions receive an implicit "this" pointer as a first argument. Whether or not am *implmentation* chooses to routinely pass an implicit "this" pointer as a first argument to VIRTUAL static member functions is unimportant (so long as overloaded function calls are resolved consistently) and may be decided by implementation convenience and efficiency,The function cannot use any non-static members anyway, so the value of "this" is irrelevant. In summary, VIRTUAL static member functions are entered in the virtual function table, may only access static data and functions, and may or may not be actually passed a "this" pointer. Non-virtual static member functions would remain unchanged. It is easy to come up with examples where this is useful. Suppose foo() was a static member function which describes class "Base". 1. Base::foo(); uses foo() as a "class" function, as opposed to an "object" function. This is ostensibly one of the reasons for having static member functions. 2. obj.foo(); is simply a way of getting to this "class" function for the class which foo is an instance of. i.e. a way of doing obj.class.foo(); 3. Certainly a class "Der" derived from Base would have its own foo(); Hence, any function which takes a Base& (or Base*) argument should be able to access either Base::foo() or Der::foo(), to describe the appropriate class. Virtual static functions would do this. Desmond. ------------------------------------------------------------------------------- Desmond D'Souza, MCC CAD Program | ARPA: dsouza@mcc.com | Phone: [512] 338-3324 Box 200195, Austin, TX 78720 | UUCP: {uunet,harvard,gatech,pyramid}!cs.utexas.edu!milano!cadillac!dsouza -- ------------------------------------------------------------------------------- Desmond D'Souza, MCC CAD Program | ARPA: dsouza@mcc.com | Phone: [512] 338-3324 Box 200195, Austin, TX 78720 | UUCP: {uunet,harvard,gatech,pyramid}!cs.utexas.edu!milano!cadillac!dsouza