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
47
votes
1 answer

Out-of-Line Virtual Method

What exactly is a out-of-line virtual method and why does it affect link times? LLVM Coding Standards says If a class is defined in a header file and has a vtable (either it has virtual methods or it derives from classes with virtual methods),…
Daniel Eggert
  • 6,665
  • 2
  • 25
  • 41
46
votes
4 answers

Can we have a virtual static method ? (c++)

Possible Duplicate: C++ static virtual members? Can we have a virtual static method (in C++) ? I've tried to compile the following code : #include using namespace std; class A { public: virtual static void f() {cout << "A's…
Ron_s
  • 1,429
  • 1
  • 14
  • 24
45
votes
7 answers

Why are private virtual methods illegal in C#?

Coming from a C++ background, this came as a surprise to me. In C++ it's good practice to make virtual functions private. From http://www.gotw.ca/publications/mill18.htm: "Guideline #2: Prefer to make virtual functions private." I also quote Eric…
Jon
  • 5,275
  • 5
  • 39
  • 51
41
votes
8 answers

Pure virtual functions in C++11

In C++98, the null pointer was represented by the literal 0 (or in fact any constant expression whose value was zero). In C++11, we prefer nullptr instead. But this doesn't work for pure virtual functions: struct X { virtual void foo() =…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
40
votes
6 answers

Can we make a class copy constructor virtual in C++

Can we make a class copy constructor virtual in C++? How to use?
user1295465
40
votes
5 answers

Print address of virtual member function

I am trying to print the address of a virtual member function. If I know which class implements the function I can write: print("address: %p", &A::func); But I want to do something like this: A *b = new B(); printf("address: %p", &b->func);…
hidayat
  • 9,493
  • 13
  • 51
  • 66
40
votes
12 answers

Alternative to c++ static virtual methods

In C++ is not possible to declare a static virtual function, neither cast a non-static function to a C style function pointer. Now, I have a plain ol' C SDK that uses function pointers heavily. I have to fill a structure with several function…
raven
  • 2,574
  • 2
  • 27
  • 49
39
votes
5 answers

How to design a C++ API for binary compatible extensibility

I am designing an API for a C++ library which will be distributed in a dll / shared object. The library contains polymorhic classes with virtual functions. I am concerned that if I expose these virtual functions on the DLL API, I cut myself from the…
shojtsy
  • 1,710
  • 3
  • 17
  • 24
38
votes
2 answers

c++ : code explanation for method prototype with const = 0

I hava a class declaration with a piece of code that I do not understand : class Weapon { public: virtual void attack() const = 0; }; What does the const = 0 part means ?
Jérémy Pouyet
  • 1,989
  • 6
  • 28
  • 55
37
votes
3 answers

How to limit memory of a OS X program? ulimit -v neither -m are working

My programs run out of memory like half of the time I run them. Under Linux I can set a hard limit to the available memory using ulimit -v mem-in-kbytes. Actually, I use ulimit -S -v mem-in-kbytes, so I get a proper memory allocation problem in the…
hectorpal
  • 711
  • 2
  • 6
  • 15
36
votes
6 answers

How do I get the complete virtual path of an ASP.NET application

How do I know the the complete virtual path that my application is currently hosted? For example: http://www.mysite.com/myApp or http://www.mysite.com/myApp/mySubApp I know the application path of HttpRequest but it only returns the folder name…
user115195
  • 363
  • 1
  • 3
  • 4
36
votes
10 answers

C# virtual static method

Why is static virtual impossible? Is C# dependent or just don't have any sense in the OO world? I know the concept has already been underlined but I did not find a simple answer to the previous question.
Toto
  • 7,491
  • 18
  • 50
  • 72
35
votes
6 answers

Detect virtual keyboard vs. hardware keyboard

I have been thinking about this a while now, and I can't figure a way to deal with it. Is there any way to detect if the user uses a virtual (software) keyboard or a traditional (hardware) keyboard? The new Windows Surface has its own keyboard in…
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123
34
votes
2 answers

Call base method at beginning or end of method?

The only similar question to this I found was this and the answer suggested having to use Reflector to find out. What about in just the majority of the cases? Generally, is the base method called first or last in a method? I noticed in some…
Ryan Peschel
  • 11,087
  • 19
  • 74
  • 136
34
votes
3 answers

Mongoose virtual fields included in toJSON by default: schemaOptions.toJSON.virtuals = true; still doesn't include virtual fields by default

I saw in another answer that in order to include the virtual fields you must do like https://groups.google.com/forum/?fromgroups#!topic/mongoose-orm/HjrPAP_WXYs var schemaOptions = { toJSON: { virtuals: true } }; which I've done; Now in the…
Totty.js
  • 15,563
  • 31
  • 103
  • 175