Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DBObject {
- private:
- . . . // state
- public:
- void saveState() { . .. }
- void loadState() { . .. }
- . . .
- }
- class StorableShape : Shape {
- private DBObj ect _store;
- alias _store this;
- this( ) {
- _store = new DBObj ect;
- }
- . . .
- }
- unittest {
- auto s = new StorableShape;
- s. draw( ) ; // call a Shape method
- s. saveState() ; // call a DBObject method
- // gets rewritten as s._store.saveState()
- Shape sh = s; // normal upcast derived -> base
- DBObj ect db = s; // rewritten as DBObject db = s._store
- }
Add Comment
Please, Sign In to add comment