Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > why not virtual static method

Reply
Thread Tools

why not virtual static method

 
 
Tony Johansson
Guest
Posts: n/a
 
      08-21-2005
Hello Experts!

I know that you can't have virtual static methods and I know what a static
method is.

A static method exist only one time no matter how many object you have. You
have this static method even if you have no objects at all. Static methods
belongs only to the class and not to the object you have.
They can only access static members.

But assume this you have a class called Shape here and a method called draw
which should be
declared as virtual static and not pure virtual. So this class Shape is a
concrete class.
Assume you have a derived class called Circle and in this class you override
this method draw.
I know that this example is not so god because how do you draw a Shape. I
just want to know
if there is any contradiction to the language to have virtual static method.
I mean that you inheric types and not object. You always have a type even if
the method is declared static.

//Tony


 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      08-21-2005
Tony Johansson wrote:

> Hello Experts!
>
> I know that you can't have virtual static methods and I know what a static
> method is.
>
> A static method exist only one time no matter how many object you have.
> You have this static method even if you have no objects at all. Static
> methods belongs only to the class and not to the object you have.


Right.

> They can only access static members.


Well, unless they get an object somehow, like:

class Foo
{
public:
static void do_something(Foo& obj)
{
obj.x = 5;
}

int x;
};

> But assume this you have a class called Shape here and a method called
> draw which should be declared as virtual static and not pure virtual. So
> this class Shape is a concrete class.
> Assume you have a derived class called Circle and in this class you
> override this method draw.
> I know that this example is not so god because how do you draw a Shape. I
> just want to know if there is any contradiction to the language to have
> virtual static method. I mean that you inheric types and not object. You
> always have a type even if the method is declared static.


Ok, let's assume you have the class Shape and some classes Circle, Rectangle
and Triangle that are derived from it. Now you call Shape::draw(), which
derived class draw() should be called and how should that be decided?

 
Reply With Quote
 
 
 
 
Bob Hairgrove
Guest
Posts: n/a
 
      08-21-2005
On Sun, 21 Aug 2005 09:18:41 GMT, "Tony Johansson"
<(E-Mail Removed)> wrote:

>Hello Experts!
>
>I know that you can't have virtual static methods and I know what a static
>method is.


[snip...]

>if there is any contradiction to the language to have virtual static method.
>I mean that you inheric types and not object. You always have a type even if
>the method is declared static.


Google: "virtual static" (method OR function)

--
Bob Hairgrove
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
I see no difference in an inheirited non-virtual method and an inheirited virtual method jlopes C++ 7 11-19-2004 07:47 PM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM
Can't access static member var from static method. Why? Markus Dehmann C++ 5 07-01-2004 04:16 PM
Why do static and non-static method names collide? =?ISO-8859-1?Q?Thomas_Gagn=E9?= Java 12 07-05-2003 04:59 PM



Advertisments