Questions tagged [virtual]

An extensible or simulated artifact

Virtual memory: Giving the appearance of having greater system memory by paging infrequently used portions of memory out to disk, and reloading them from disk only when referenced.

Virtual hard disk: A software simulation of a hard disk.

Virtual method: a function that can be overridden in descendant classes to extend or replace existing functionality. This is a key aspect of polymorphism.

Virtual reality: A simulation of experience achieved by coordinating visual, audible, and tactile stimuli

3155 questions
425
votes
12 answers

Virtual/pure virtual explained

What exactly does it mean if a function is defined as virtual and is that the same as pure virtual?
Justin
  • 9,419
  • 7
  • 34
  • 41
275
votes
7 answers

Why use 'virtual' for class properties in Entity Framework model definitions?

In the following blog: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx The blog contains the following code sample: public class Dinner { public int DinnerID { get; set; } public string…
Gary Jones
  • 3,047
  • 4
  • 17
  • 14
192
votes
6 answers

Can you write virtual functions / methods in Java?

Is it possible to write virtual methods in Java, as one would do in C++? Or, is there a proper Java approach which you can implement that produces similar behavior? Could I please have some examples?
yonatan
  • 2,133
  • 3
  • 15
  • 8
178
votes
20 answers

C++ static virtual members?

Is it possible in C++ to have a member function that is both static and virtual? Apparently, there isn't a straightforward way to do it (static virtual member(); is a compile error), but is there at least a way to achieve the same…
cvb
  • 4,321
  • 6
  • 26
  • 19
103
votes
5 answers

navigation property should be virtual - not required in ef core?

As I remember in EF navigation property should be virtual: public class Blog { public int BlogId { get; set; } public string Name { get; set; } public string Url { get; set; } public string Tags { get; set; } public…
98
votes
5 answers

How to do virtual file processing?

So for creating files I use the following: fileHandle = open('fileName', 'w') then write the contents to the file, close the file. In the next step I process the file. At the end of the program, I end up with a "physical file" that I need to…
Steve Grafton
  • 1,821
  • 4
  • 17
  • 18
95
votes
12 answers

What are Virtual Methods?

Why would you declare a method as "virtual". What is the benefit in using virtual?
mtnclimber10
93
votes
5 answers

CRTP to avoid dynamic polymorphism

How can I use CRTP in C++ to avoid the overhead of virtual member functions?
Amit
89
votes
4 answers

c++ overloaded virtual function warning by clang?

clang emits a warning when compiling the following code: struct Base { virtual void * get(char* e); // virtual void * get(char* e, int index); }; struct Derived: public Base { virtual void * get(char* e, int index); }; The warning…
Jean-Denis Muys
  • 6,772
  • 7
  • 45
  • 71
85
votes
6 answers

Why doesn't polymorphism work without pointers/references?

I did find some questions already on StackOverflow with similar title, but when I read the answers, they were focusing on different parts of the question, which were really specific (e.g. STL/containers). Could someone please show me, why you must…
user997112
  • 29,025
  • 43
  • 182
  • 361
83
votes
4 answers

The difference between virtual, override, new and sealed override

I'm pretty confused between some concepts of OOP: virtual, override, new and sealed override. Can anyone explain the differences? I am pretty clear that if the derived class method is to be used, one can use the override keyword so that the base…
xorpower
  • 17,975
  • 51
  • 129
  • 180
78
votes
5 answers

virtual assignment operator C++

Assignment Operator in C++ can be made virtual. Why is it required? Can we make other operators virtual too?
Kazoom
  • 5,659
  • 16
  • 56
  • 69
75
votes
1 answer

virtual inheritance

What is the meaning of "virtual" inheritance? I saw the following code, and didn't understand the meaning of the keyword virtual in the following context: class A {}; class B : public virtual A;
Gal Goldman
  • 8,641
  • 11
  • 45
  • 45
74
votes
1 answer

Difference between target google APIs and target android

I'm developing android with SDK 2.3.3 using Eclipse IDE. As you all know to run my app, I should generate virtual device. From 'create new AVD' window, I can see many targets. There are 2 targets for API level 10 such as 'android 2.3.3' and Google…
allbory
  • 743
  • 1
  • 5
  • 5
70
votes
7 answers

What are the performance implications of marking methods / properties as virtual?

Question is as stated in the title: What are the performance implications of marking methods / properties as virtual? Note - I'm assuming the virtual methods will not be overloaded in the common case; I'll usually be working with the base class…
Erik Forbes
  • 35,357
  • 27
  • 98
  • 122
1
2 3
99 100