<p>Consider these classes.</p>

<pre><code>class Base
{
   ...
};

class Derived : public Base
{
   ...
};
</code></pre>

<p>this function</p>

<pre><code>void BaseFoo( std::vector&lt;Base*&gt;vec )
{
    ...
}
</code></pre>

<p>And finally my vector</p>

<pre><code>std::vector&lt;Derived*&gt;derived;
</code></pre>

<p>I want to pass <code>derived</code> to function <code>BaseFoo</code>, but the compiler doesn't let me. How do I solve this, without copying the whole vector to a <code>std::vector&lt;Base*&gt;</code>?</p>

one option is to use a template
```
```
template<typename T>
void BaseFoo( const std::vector<T*>& vec)
{
 ...
}
```
```
The drawback is that the implementation has to be in the header and you will get a little code bloat. You will wind up with different functions being instantiated for each type, but the code stays the same. Depending on the use case it's a quick and dirty solution.
Edit, I should note the reason we need a template here is because we are trying to write the same code for unrelated types as noted by several other posters. Templates allow you do solve these exact problems. I also updated it to use a const reference. You should also pass "heavy" objects like a vector by const reference when you don't need a copy, which is basically always.