Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ImmutableLib.h
- struct LibType { ... }
- LibType* lib_get() { ... }
- LibType* lib_doVoodoo(LibType* arg) { ... }
- // MyInterface.h
- struct OpaqueType;
- class MyInterface {
- virtual OpaqueType* get() = 0;
- virtual OpaqueType* doVoodoo(OpaqueType* arg) = 0;
- };
- // MyImpl.h
- class MyImpl : public MyInterface {
- ...
- }
- // MyImpl.cpp
- #include <ImmutableLib.h>
- struct OpaqueType {
- // Should anything go here?
- }
- OpaqueType* MyInterface::get() {
- return (OpaqueType*)lib_get(); // type-safe way to do this?
- }
- OpaqueType* MyInterface::doVoodoo(OpaqueType* arg) {
- return (OpaqueType*)lib_doVoodoo((LibType*)arg); // type-safe way to do this?
- }
- // main.cpp
- #include "MyImpl.h"
- int main()
- {
- MyInterface* x = new MyImpl;
- OpaqueType* p = x.get();
- OpaqueType* q = x.doVoodoo(p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement