A counter-intuitive function call in C++
<p>A quite simple C++ code:</p>

<pre><code>#include &lt;iostream&gt;

using namespace std;

class Foo {
public:
    void callPrint() {
        print();
    }
    void print() {
        cout &lt;&lt; "Foo" &lt;&lt; endl;
    }
};

class Bar : public Foo {
public:
    void print() {
        cout &lt;&lt; "Bar" &lt;&lt; endl;
    }
};

int main() {
    Bar b;
    b.callPrint();

    return 0;
}
</code></pre>

<p>Here the output is "Foo". And if I make the "Foo::print()" virtual, the output will be "Bar". My questions are:</p>

<ol>
<li><p>When the <code>Foo::print()</code> is non-virtual, why is it called when a <code>Bar</code> object is passed to <code>Foo::callPrint()</code>, is there type (both static and dynamic) mismatch?</p></li>
<li><p>When <code>Foo:callPrint()</code> is virtual, the call <code>b.callPrint()</code> is not via reference or pointer, however <code>Bar::print()</code> is called. This is not so-called polymorphism, then how to explain this behavior, according to either language definition or compiler implementation?</p></li>
</ol>