And people, don't blast me if this is a stupid question as ive only got very little knowledge of programming
![Stick Out Tongue](https://www.phoronix.com/forums/core/images/smilies/tongue.png)
#include "lib.h" #include <stdio.h> void lib::foo(int i) { printf("%d\n", i); } void lib::del() { delete this; } lib *new_lib() { return new lib; }
class lib { public: void foo(int i); void del(); }; lib *new_lib();
#include "lib.h" int main() { lib *l = new_lib(); l->foo(10); l->foo(20); l->del(); return 0; }
10 20
class lib { private: int j; public: lib(); ~lib(); void foo(int i); virtual void add(int i); void del(); }; lib *new_lib();
#include "lib.h" #include <stdio.h> lib::lib() : j(5) { printf("constructor\n"); } lib::~lib() { printf("destructor\n"); } void lib::foo(int i) { printf("%d\n", j); add(i); } void lib::add(int i) { j += i; } void lib::del() { delete this; } lib *new_lib() { return new lib; }
constructor 5 15 destructor
[zhasha@ztoshiba Desktop]$ LD_LIBRARY_PATH=. ./foo constructor 5 15 ./foo: symbol lookup error: ./foo: undefined symbol: _ZN3lib3delEv
-Bsymbolic When creating a shared library, bind references to global symbols to the definition within the shared library, if any. Normally, it is possible for a program linked against a shared library to override the definition within the shared library. This option is only meaningful on ELF platforms which support shared libraries.
MyClass *foo; dlopen("myclass.so"); dl_class_sym(MyClass, "MyClass"); foo = new MyClass();
MyClass *foo; dlopen("myclass.so"); dl_class_sym(MyClass, "MyClass"); foo = new MyClass();
extern "C" IDirect3D9 * Direct3DCreate9( UINT sdk_version ) { IDirect3D9 *d3d9 = NULL; /* Why? just because. */ if (sdk_version != D3D_SDK_VERSION) { return NULL; } try { d3d9 = new IDirect3D9; } catch (std::bad_alloc e) { if (d3d9) { delete d3d9; } return NULL; } return d3d9; }
#include <d3d9.h> ... LPDIRECT3D9 d3d9; d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
Leave a comment: