Advertisement
quantumech

Untitled

Apr 23rd, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <emscripten/bind.h>
  2. #include <iostream>
  3.  
  4. using namespace emscripten;
  5.  
  6. class BaseClass
  7. {
  8.     public:
  9.  
  10.     BaseClass(){}
  11.  
  12.     void Hello()
  13.     {
  14.  
  15.     }
  16.  
  17.     void Goodbye()
  18.     {
  19.         std::cout << "Goodbye" << std::endl;
  20.     }
  21. };
  22.  
  23. class SubClass : public BaseClass
  24. {
  25.     public:
  26.     void Hello()
  27.     {
  28.         std::cout << "Hello" << std::endl;
  29.     }
  30.  
  31.     int Add(int a, int b)
  32.     {
  33.         return a + b;
  34.     }
  35. };
  36.  
  37. EMSCRIPTEN_BINDINGS(Module)
  38. {
  39.     class_<BaseClass>("BaseClass") // Register base class and all its attributes
  40.         .constructor<>()
  41.         .function("Hello", &BaseClass::Hello)
  42.         .function("Goodbye", &BaseClass::Goodbye);
  43.  
  44. //Notice the extra parameter passed to 'class_' template
  45. //                      |
  46. //                      V
  47.     class_<SubClass, base<BaseClass>>("SubClass") // SubClass will also have all the attributes of baseclass
  48.         .constructor<>()
  49.         .function("Hello", &SubClass::Hello)
  50.         .function("Add", &SubClass::Add);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement