From 0292059f4a16434600564cfa3f0ad2309a508a54 Mon Sep 17 00:00:00 2001 From: tpearson Date: Wed, 24 Feb 2010 17:43:19 +0000 Subject: Added libksquirrel for KDE3 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/libraries/libksquirrel@1095624 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- doc/sources/c++/main.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 doc/sources/c++/main.cpp (limited to 'doc/sources/c++/main.cpp') diff --git a/doc/sources/c++/main.cpp b/doc/sources/c++/main.cpp new file mode 100644 index 0000000..b8fb8cd --- /dev/null +++ b/doc/sources/c++/main.cpp @@ -0,0 +1,44 @@ +#include "polygon.hpp" + +#include +#include + +int main() +{ + using std::cout; + using std::cerr; + + // load the triangle library + void* triangle = dlopen("./triangle.so", RTLD_LAZY); + + if (!triangle) + { + cerr << "Cannot load library: " << dlerror() << '\n'; + return 1; + } + + // load the symbols + create_t* create_triangle = (create_t*) dlsym(triangle, "create"); + destroy_t* destroy_triangle = (destroy_t*) dlsym(triangle, "destroy"); + + if (!create_triangle || !destroy_triangle) + { + cerr << "Cannot load symbols: " << dlerror() << '\n'; + return 1; + } + + // create an instance of the class + polygon* poly = create_triangle(); + + // use the class + poly->set_side_length(7); + cout << "The area is: " << poly->area() << '\n'; + + // destroy the class + destroy_triangle(poly); + + // unload the triangle library + dlclose(triangle); + + return 0; +} -- cgit v1.2.3