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.
我无法理解这是如何工作,因为分配,部署,和运营商都是纯虚拟的,所以他们是各自的类实际上并没有定义这些功能。
实际上,我怎么叫他们在这里有关系吗? – user1903336
因为如果他们有函数定义你会使用它。 'char * p = a.allocate(5)'等 –