function parameters, polymorphism
<p>I have the following piece of code. I was wondering if there was a way to modify foo(A a) so that calling it would have the result as in the commented code below, but without overloading. </p>

<pre><code>class A { 
  public: virtual void print() { std::cout &lt;&lt; "A\n"; } };
class B : public A {
  public: virtual void print() { std:cout &lt;&lt; "B\n"; }
};

void foo( A a ) { a.print(); } // How to modify this, so it chooses to use B's print()?
// void foo( B a ) { a.print(); } // now, this would work! 

int main( void ) { 
  A a; 
  foo( a ); // prints A
  B b;
  foo(b);  // prints A, but I want it to print B
}
</code></pre>

<p>Is this possible at all? If not, why?</p>
