This occurs to me that I can add
template<typename T>
class ISock {
public:
Message Recv() {
return static_cast<T*>(this)->Recv();
};
~ISock(){
static_cast<T*>(this)->~ISock();
};
// use the following complementary...
T* operator->(){
return static_cast<T*>(this);
};
void Other override {
(*this)->Other();
}
};
This allows more flexibility in function definition and reduce boilerplates, for example, if I have
class MockSock : ISock<MockSock> {
public:
...
void peculiarFunction(int){
...
}
Then I may use the peculiarFunction in defining fn(ISock<MockSock> m)
or even with if constexpr for specialization. I am wondering whether it's a good practice to
- provide a .inner() method
- to overload it as operator-> for simplicity in coding.
Aucun commentaire:
Enregistrer un commentaire