Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. using namespace std;
  2. class Base
  3. {
  4. public:
  5. int ClassID; // Used only by derived classes
  6. string Name;
  7. shared_ptr<Base> Parent; // For TreeCtrl-like hierarchy
  8. }
  9. class DerivedA : public Base
  10. {
  11. public:
  12. double Length;
  13. double Width;
  14. double Height;
  15. }
  16. class DerivedB: public Base
  17. {
  18. public:
  19. double Radius;
  20. }
  21.  
  22. class Controller
  23. {
  24. public:
  25. vector<shared_ptr<Base>> Objects;
  26. void CreateObject(int class_id, string name, shared_ptr<Base> parent)
  27. {
  28. shared_ptr<Base> temp;
  29. switch(class_id)
  30. {
  31. case DERIVEDA: // enum definition assumed
  32. temp = make_shared<DerivedA>(name, parent); // constructors assumed
  33. break;
  34. case DERIVEDB:
  35. temp = make_shared<DerivedB>(name, parent);
  36. break;
  37. }
  38. Objects.push_back(temp);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement