fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct Data{
  7. int m;
  8. double u;
  9. long f;
  10.  
  11. Data(int kj, double lh, long fg)
  12. {
  13. m = kj;
  14. u = lh;
  15. f = fg;
  16. }
  17.  
  18. Data& operator= (const Data& mydat)
  19. {
  20. m = mydat.m;
  21. u = mydat.u;
  22. f = mydat.f;
  23.  
  24. return *this;
  25. }
  26. };
  27.  
  28. struct Example
  29. {
  30. vector <Data> m;
  31. string k;
  32.  
  33. Example (string info, Data* data)
  34. {
  35. m.push_back(Data(2,-9.32322,-324332));
  36. k = info; *data = m.back();
  37. }
  38.  
  39. ~Example()
  40. {
  41. cout << "Deleted!\n";
  42. }
  43. };
  44.  
  45. int main()
  46. {
  47. Data* flv = new Data(1,2,3);
  48. std::cout << flv->m << std::endl;
  49. Example doesnotwork("", flv);
  50. std::cout << flv->m << std::endl;
  51. return 0;
  52. }
Success #stdin #stdout 0s 2988KB
stdin
Standard input is empty
stdout
1
2
Deleted!