Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The main difference between Java and C++ is the fact that in Java every function is <code>virtual</code>.</p> <p>Historically when C++ have been developed the fact of placing an abastraction layer between every function call (that is what happens using a virtual method table) wasn't something you did want for every method call because a virtual method invocation is slower.</p> <p>So what happens is that you must specify that a method must be called through <a href="http://en.wikipedia.org/wiki/Dynamic_dispatch" rel="nofollow"><strong>dynamic binding</strong></a>, otherwise the method is chosen during compile time according to the declaration of the variable. This means that if you declare <code>Base *b = new Derived()</code> and you call a method on <code>b</code> which is not virtual then method is chosen at compile time and it will be a <code>Base::method</code>.</p> <p>The motto is <em>you don't pay for what you don't use</em> and that's it.</p> <p>Interfaces in C++ doesn't exist, but you can have a class with just pure virtual functions which behave basically in the same way. Actually you can have two kind of virtual methods:</p> <pre><code>class Base { virtual void method() { //implementation } virtual void pureMethod() = 0; } </code></pre> <p>First <code>method()</code> is virtual and obeys to dynamic binding but it is implemented even in Base class while <code>pureMethod()</code> still obeys to dynamic binding but it's declared as pure virtual so it doesn't have any implementation, thus <code>Base</code> cannot be instantiated as it is and you need to subclass it and override at least the pure virtual method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload