给定
class Allocator {
public:
virtual char *allocate(unsigned int size)=0;
// EFF: allocates a character buffer of size characters
virtual void dispose(char *buf)=0;
// REQ: buf was allocated by this allocator
// EFF: release memory previously allocated.
};
class Translator {
public:
virtual char *operator()(const char *s, Allocator &a) = 0;
// EFF: returns a translation of the C-string s as
// another C-string, where the translation
// C-string is allocated by a.
};
假设您要实现以下内容:
void printTranslatedArgs(int argc, char *argv[],
Translator &t, Allocator &a);
// REQ: argc/argv are in the form of program arguments
// EFF: prints the translated command line.
我无法理解这是如何工作的,因为 allocate、dispose 和 operator 是纯虚拟的,所以它们各自的类实际上并没有定义这些函数。