Type erasure - is that how you call it?
How boost::shared_ptr stores its deleter and how boost::function stores its function object?
Is there any tutorial that teaches the trick?
What is the run-time cost of using type-erased function objects?
|
Type erasure - is that how you call it? How Is there any tutorial that teaches the trick? What is the run-time cost of using type-erased function objects? |
|||||||||
|
|
The idea is simple, you define a base class that has an interface with the functionality you need, and then inherit from it. Since the type erased class uses only that interface, the actual type underneath is forgotten and erased. Alternatively, if the only needed interface can be expressed as free functions you can store pointers to the free functions.
This is a really simplified smart pointer, but the idea is there. In the particular case of |
|||||||||||||||||||||
|