In the proxy section the Design Patter from the Gang of Four says:
Overloading the member access operator isn't a good solution for every kind of proxy. Some proxies need to know precisely which operation is called, and overloa开发者_如何学Cding the member access operator doesn't work in those cases.
[...]
In that case we must manually implement each proxy operation that forwards the request to the subject.
[...]
Typically all operations verify that the request is legal, that the original object exists, etc., before forwarding the request to the subject. It's tedious to write this code again and again. So it's common to use a preprocessor to generate it automatically.
OK, which preprocessor and how in C++?
The canonical reference for implementing some Design Patterns in C++ is
Modern C++ Design by Alexandrescu
Another good reference for the techniques of using the type system of C++ for building design patterns is the book on
C++ Templates by Vandevoorde & Josuttis
And the reference for template meta-programming is
C++ Template Metaprogramming: Concepts, Tools and Techniques from Boost and Beyond by David Abrahams and Alesky Gurtovoy.
I think they mean automated generation of the wrapper code around the subject class. An example would be wrapper code generated by the SWIG project.
精彩评论