Talk:Virtual function

From Wikipedia, the free encyclopedia
Jump to: navigation, search
WikiProject Computing (Rated Start-class)
WikiProject icon This article is within the scope of WikiProject Computing, a collaborative effort to improve the coverage of computers, computing, and information technology on Wikipedia. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks.
Start-Class article Start  This article has been rated as Start-Class on the project's quality scale.
 ???  This article has not yet received a rating on the project's importance scale.
 

Untitled[edit]

I think this article needs a section on Default Virtual Methods.

This would qualify the fact that the child has a option of -

[1] Override with its own virtual method (polymorph) [2] use Default Virtual Method (in the parent) [3] Override and also use the parents default method

This section should also state one or two languages that support this.

Shawnk Fri 06/23/2006

This article has a very poor definition of virtual function, and a completely incorrect one of pure virtual function. You'd fail my interview!

C++/Java Only[edit]

This article indicates that these ideas are generally part of Object Oriented Programming, but they're not. There are plenty of Object Oriented Programming languages where the semantics of "virtual" or "pure virtual" methods are arrived at by very different means. Jfm3 (talk) 06:12, 18 July 2008 (UTC)

Anybody like to do the C# version of the examples? —Preceding unsigned comment added by 82.18.197.179 (talk) 10:29, 2 October 2008 (UTC)

there should be mention that in Java all methods are virtual by default - dddd (talk) 18:50, 26 June 2014 (UTC)

Bad definition[edit]

I do not belive that this is the correct defenition and in any case, the example is that of polymorphism and does nothing in the way of explaining what does the use of the keyword virtual help.

Definition Fix[edit]

I made an attempt at correcting the definition. I believe that it is now correct (if not complete).

Andy 16:10, 28 September 2006 (UTC)

Example Fix[edit]

Even though it's not relevant to the topic discussed I think Wikipedia examples should not include code with such obvious memory leaks (four instances of Animal are allocated but never released). I'll fix this. --Liss 16:29, 5 December 2006 (UTC)

Error: C++/pure virtual functions[edit]

In c++, pure virtual functions may have definitions. So I think this article is wrong there. (e.g. "http://www.gotw.ca/gotw/031.htm")

Why virtual[edit]

Why is this concept called virtual? --Abdull 14:09, 4 April 2007 (UTC)

Output for undefined[edit]

If the behavior of an action is undefined, it simply does not make any sense to present Output here.

What that output represent is how some implementation of a c++ compiler handles the situation.

By not even mentioning what compiler was used, showing the output becomes both pointless but also dangerous (it is *not* safe to assume that the output is what one's going to see everytime everwhere).


84.191.199.138 (talk) 15:34, 21 September 2008 (UTC)

C# abstract methods[edit]

This article needs some mention of the (bizarre in my view) requirement for implementations of abstract methods in derived classes to specify the override keyword. Needs somebody who knows C# inside out and I don't qualify!

Yaqoobj (talk) 10:58, 16 September 2009 (UTC)

C++ example[edit]

I wouldn't declare the destructors as virtual in the C++ example. It's just confusing.

212.126.224.100 (talk) 14:07, 4 March 2011 (UTC)

OK, I see that it is recommended to declare destructors as virtual in general. But I still think it may be more appropriate to leave the virtual out in the first example.
212.126.224.100 (talk) 14:17, 4 March 2011 (UTC)

Please simplify[edit]

The sentence: "In the example below having no virtual destructor, while deleting an instance of class B will correctly call destructors for both B and A if the object is deleted as an instance of B, an instance of B deleted via a pointer to its base class A will produce undefined behaviour." is a bit long and at least for me (not a native english speaker) the meaning of this sentence is left unclear. Please someone consider reading it and making it clearer. Thank you. 188.238.11.76 (talk) 17:10, 11 April 2011 (UTC)

Code samples[edit]

There's an absurd amount of code in this article, maybe the examples should be cut down to one or two languages? – Acdx (talk) 13:04, 19 June 2011 (UTC)

Why such a complex example to illustrate the wrong usage of virtual method ?[edit]

In one of the example programs, a static nested class has been used to illustrate the wrong usage of virtual functions in the constructor. A simpler example would have done. — Preceding unsigned comment added by Arpit.gupta85 (talkcontribs) 07:39, 20 December 2011 (UTC)