Thanks both of you for answers.
apologies as my english is not so good, so may be i wasn't clear about the question.
@firstPerson, its not designing question, and I can show lot of examples where you need this kind of generic library class, for instance..
We want to implement a SmartPointer generic class for our use, now we can implement smart pointer in so many different ways. @Mike, now here we can provide the policy classes for different different ways/mechanisms/policy.
In our SmartPointer class we want to provide a way so that user of this class can do certain check before this object get deallocated.
Now lets say there are completely two different kind of object.
one is class MySpecialSocket, this wants to check if the socket has been closed and there are more data to read/write before get deallocating.
another class PausedGame, wants to provide another method to check if the game is still paused, but pointer is getting deleted!!!!
user of SmartPointer may not want to do the check also as his object might not need any check.
template <T>
class SmartPointer
{
//Smart pointer implementation
~SmartPointer{
if(condition doesn't match)
throw "Not Good, we know we shouldn't throw exception from here but still people should know";
}
}
below is the code of those two class:
class MySpecialSocket{
//Implementation
//this is the check method we have to provide to SmartPointer
bool isSocketStillOpen{
}
}
code for paused game
class PausedGame{
//implementaion
//this is the check method we have to provide to SmartPointer
bool isGameStillPaused{
}
}
Thanks for taking your valuable time to think about it.
Now how you will solve it? as there are several solutions to this, i know only one, which i am trying to do now..