Guest User

Untitled

a guest
Nov 25th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include "Link.h"
  2.  
  3. #include <QDebug>
  4.  
  5. template <class ValueType>
  6. class Object
  7. {
  8. public:
  9. Object() {}
  10.  
  11. ValueType value() const {
  12. return _value;
  13. }
  14.  
  15. void setValue(const ValueType &value) {
  16. _value = value;
  17. }
  18.  
  19. void print() const {
  20. qDebug() << "object:" << value().toString();
  21. }
  22.  
  23. void link(const Object<ValueType> *other) {
  24. Link *ln = new Link();
  25. ln->setFromObject(this);
  26. ln->setToObject(other);
  27. _links.append(ln);
  28. }
  29.  
  30. private:
  31. ValueType _value;
  32. QList<Link*> _links;
  33.  
  34. };
  35.  
  36. #ifndef LINK_H
  37. #define LINK_H
  38.  
  39. #include "Object.h" //упс
  40. template <class ValueType>
  41. class Link
  42. {
  43. public:
  44. Link() {}
  45.  
  46. Object<ValueType> *fromObject() const {
  47. return _fromObject;
  48. }
  49.  
  50. void setFromObject(Object<ValueType> *fromObject) {
  51. _fromObject = fromObject;
  52. }
  53.  
  54. Object<ValueType> *toObject() const {
  55. return _toObject;
  56. }
  57.  
  58. void setToObject(Object<ValueType> *toObject) {
  59. _toObject = toObject;
  60. }
  61.  
  62.  
  63. private:
  64. Object<ValueType> *_fromObject;
  65. Object<ValueType> *_toObject;
  66. };
  67.  
  68. template <class T>
  69. class Object<T>;
  70.  
  71. template <class ValueType, class LinkType>
  72. class Object
  73. {
  74. LinkType<ValueType>
  75. ...
  76.  
  77. template <class ValueType>
  78. class Link
  79. {
  80. ...
  81. Object<ValueType, Link<ValueType> *_someObject;
  82.  
  83. template<class T>
  84. class Object;
Add Comment
Please, Sign In to add comment