daily pastebin goal
71%
SHARE
TWEET

Untitled

a guest Aug 13th, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ImmutableLib.h
  2.  
  3. struct LibType { ... }
  4. LibType* lib_get() { ... }
  5. LibType* lib_doVoodoo(LibType* arg) { ... }
  6.  
  7.  
  8. // MyInterface.h
  9. struct OpaqueType;
  10.  
  11. class MyInterface {
  12.    virtual OpaqueType* get() = 0;
  13.    virtual OpaqueType* doVoodoo(OpaqueType* arg) = 0;
  14. };
  15.  
  16.  
  17. // MyImpl.h
  18. class MyImpl : public MyInterface {
  19.  ...
  20. }
  21.  
  22.  
  23. // MyImpl.cpp
  24. #include <ImmutableLib.h>
  25.  
  26. struct OpaqueType {
  27.   // Should anything go here?
  28. }
  29.  
  30. OpaqueType* MyInterface::get() {
  31.   return (OpaqueType*)lib_get(); // type-safe way to do this?
  32. }
  33.  
  34. OpaqueType* MyInterface::doVoodoo(OpaqueType* arg) {
  35.   return (OpaqueType*)lib_doVoodoo((LibType*)arg); // type-safe way to do this?
  36. }
  37.  
  38.  
  39. // main.cpp
  40. #include "MyImpl.h"
  41.  
  42. int main()
  43. {
  44.   MyInterface* x = new MyImpl;
  45.   OpaqueType* p = x.get();
  46.   OpaqueType* q = x.doVoodoo(p);
  47.  
  48.   return 0;
  49. }
RAW Paste Data
Top