This is useful when you are squeezing performance.
Calling a virtual function is slower than calling a non-virtual
function, and makes it hard for the compiler to perform certain
optimizations. Therefore there is a cost in using virtual functions.
In most cases, that's not a problem as the overhead is usually
negligible. However, in some cases you absolutely need every bit of
performance you can get, meaning that you may not be able to afford
virtual functions.
--
Zhanyong
So for your example:
MyConnectionHandler::createConnection(ConcretePacketStream *pStream);
That function has to to be
template<typename T>
void createConnection(T* pStream)
{
//...
}
or MyConnectionHandler has to be a class template
template<typename T>
class MyConnectionHandler
{
public:
void createConnection(T* Stream);
}
and then in your test case you can instantiate the template with either
the ConcretePacketStream or the MockPacketStream
TEST(Stream, createPacketStream)
{
MyConnectionHandler<MockPacketStream> mch;
MockPacketStream mpt;
// set expectations on mpt ...
mch.createPacketStream(&mpt)
}
or in the case of a member template
TEST(Stream, createPacketStream)
{
MyConnectionHandlermch;
MockPacketStream mpt;
// set expectations on mpt ...
mch.createPacketStream(&mpt)
}
Regards,
Bruce
--- On Wed, 4/15/09, geira <geir.a...@gmail.com> wrote:
Geir, the recipe says "Then you tell your template code which
implementation to use by instantiating it with different template
arguments." I agree it's a bit too abstract and will benefit from
some concrete examples. I'll edit the wiki soon to add Bruce's
examples.
Cheers,
--
Zhanyong