fork(3) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. class Winery
  6. {
  7. public:
  8.  
  9. Winery(const char * const name, const char * const location, const int acres, const int rating) :
  10. name(strdup(name)),
  11. location(strdup(location)),
  12. acres(acres),
  13. rating(rating)
  14. {
  15. }
  16.  
  17. virtual ~Winery(void)
  18. {
  19. free(name);
  20. free(location);
  21. }
  22.  
  23. const char * const getName() const { return name; }
  24. const char * const getLocation() const { return location; }
  25. const int getAcres() const { return acres; }
  26. const int getRating() const { return rating; }
  27.  
  28. private:
  29. char *name;
  30. char *location;
  31. int acres;
  32. int rating;
  33. };
  34.  
  35.  
  36.  
  37. struct Node
  38. {
  39. Node(const Winery& winery);
  40. Winery item;
  41. };
  42.  
  43. Node::Node(const Winery& winery) :
  44. item(winery.getName(), winery.getLocation(), winery.getAcres(), winery.getRating())
  45. {
  46. }
  47.  
  48. int main()
  49. {
  50. Winery winery("Mission Hill Winery", "Kelowna, BC, Canada", 646, 4);
  51.  
  52. Node node(winery);
  53.  
  54.  
  55. printf("%s\n", node.item.getName());
  56. printf("%s\n", node.item.getLocation());
  57. printf("%i\n", node.item.getAcres());
  58. printf("%i\n", node.item.getRating());
  59. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
Mission Hill Winery
Kelowna, BC, Canada
646
4