Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 17th, 2005, 09:15 AM
Tony Johansson
Guest
 
Posts: n/a
Default static member function

Hello experts!

Why is not possible to have virtual static members

Many thnakn

//Tony


  #2  
Old August 17th, 2005, 09:25 AM
Raghavendra Mahuli
Guest
 
Posts: n/a
Default Re: static member function

Hello,
virtual itself implies dynamic binding....
how can it be mixed with static??



"Tony Johansson" <johansson.andersson@telia.com> wrote in message
news:EhCMe.31690$d5.185289@newsb.telia.net...[color=blue]
> Hello experts!
>
> Why is not possible to have virtual static members
>
> Many thnakn
>
> //Tony
>
>[/color]


  #3  
Old August 17th, 2005, 09:45 AM
Greg
Guest
 
Posts: n/a
Default Re: static member function


Tony Johansson wrote:[color=blue]
> Hello experts!
>
> Why is not possible to have virtual static members
>
> Many thnakn
>
> //Tony[/color]

Can you describe what a virtual static function would mean?

I suspect that one reason that C++ has been reluctant to add support
for virtual static functions, is that no one seems to know what one is.

Greg

  #4  
Old August 17th, 2005, 09:55 AM
Robben
Guest
 
Posts: n/a
Default Re: static member function


Tony Johansson wrote:[color=blue]
> Hello experts!
>
> Why is not possible to have virtual static members
>
> Many thnakn
>
> //Tony[/color]
[color=blue]
>From your postings over the period of time, I find that you are on a[/color]
good mission to explore c++. I appreciate your eagerness but I would
advise you to find if a similar query has already been posted.
Try seaching on "static virtual" on either comp.lang.c++ or
comp.lang.c++.moderated, you will get very good information.

I searched through the list and found quite good information regarding
your query.


Best of luck.

Thank you.

  #5  
Old August 17th, 2005, 01:25 PM
Girish Shetty
Guest
 
Posts: n/a
Default Re: static member function

Its because,
Static means, with out creating object of that class, you can acccess it. It
means, it will be resolved during compilation time.
Where in, virtual functions, means, there will be virtual table creation,
virtual pointer assignment mechanism and that function call will be
determined during runtime( if we use, either, pointer or reference of base
ptr to access). So, this goes with run-time.

These two operations are totally going in opposite direction. So, its not
allowed and more over it does not make any valid sense.

Lets take one more example, virtual inline functions. We all know that
inline is just a request to the compiler. And if we call inline function
which is virtual, using pointer or reference of Base, then inline request
will be rejected and virtual comes in to picture.

But where in, static and virtual, both are not request.. so, its not
allowed.

Regards
Girish


"Tony Johansson" <johansson.andersson@telia.com> wrote in message
news:EhCMe.31690$d5.185289@newsb.telia.net...[color=blue]
> Hello experts!
>
> Why is not possible to have virtual static members
>
> Many thnakn
>
> //Tony
>
>[/color]


  #6  
Old August 17th, 2005, 05:45 PM
Jay Nabonne
Guest
 
Posts: n/a
Default Re: static member function

On Wed, 17 Aug 2005 01:32:29 -0700, Greg wrote:
[color=blue]
>
> Tony Johansson wrote:[color=green]
>> Hello experts!
>>
>> Why is not possible to have virtual static members
>>
>> Many thnakn
>>
>> //Tony[/color]
>
> Can you describe what a virtual static function would mean?
>
> I suspect that one reason that C++ has been reluctant to add support
> for virtual static functions, is that no one seems to know what one is.
>[/color]
(The following are my definitions. They probably diverge from the standard
in the details.)

### Function requirements: "member" vs. "static"

A normal member function is one that requires an object *within the body
of the function*. It can be considered an "object level" function.

A static function is one that does not have an object instance passed into
it. It could be considered a "class level" function.

### Dispatch: "compile-time" vs. "run-time" binding

A call to a function can be bound at compile time ("statically" (ugh!)) or
at run time (dynamically). The latter is what virtual functions give you.

These above concepts are orthogonal to each other. You get four
combinations:

1) Object member function bound at compile time ("normal" object function
call: o->fun()).

2) Static function bound at compile time (ClassName::fun())

3) Object member function bound at run time ("virtual" function call:
o->vfun()

4) Static function bound at run time through an object instance (o->svfun())

Case number 4 is "virtual static" and requires an object to bind the
function, but the function call itself is "static", i.e. the function does
not require an object within its body and semantically is not an object
member function. You just use the object to dispatch to the right static
function.

I have wanted this in the past for dynamically invoking class-level
functions that are also invoked elsewhere without an object (static
binding). I usually end up with a static function for static binding *and*
a virtual function calling it for dynamic dispatch, but then I need to use
some less-than-ideal naming since they can't be called the same thing in
the class.

To the OP:

The best argument I've heard why this feature doesn't work is that if you
have a "vs" function then try to call *another* "vs" function
from within the first that you call, there is no object to dispatch with.
The chain is broken. Once you look at it from that perspective, you
realize a first-level call would work, but anything after that would be
limited enough to break normal C++ semantics (in my opinion).

- Jay

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles