Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. class MyClass1 {
  2. public:
  3. MyClass1() {
  4. printf( "constructorn" );
  5. }
  6. ~MyClass1() {
  7. printf( "destructorn" );
  8. }
  9. int var1;
  10. std::string str;
  11. };
  12.  
  13. std::vector< MyClass1 > testArr;
  14.  
  15. MyClass1 gr1;
  16.  
  17. gr1.var1 = 111;
  18. testArr.push_back( gr1 );
  19.  
  20. gr1.var1 = 122;
  21. testArr.push_back( gr1 );
  22.  
  23. printf( "testArr.at( 1 ).var1 = %in", testArr.at( 1 ).var1 );
  24.  
  25. #include <iostream>
  26. #include <cstdio>
  27. #include <vector>
  28.  
  29. using namespace std;
  30.  
  31. class MyClass1 {
  32. public:
  33. MyClass1() {
  34. printf( "constructorn" );
  35. }
  36. ~MyClass1() {
  37. printf( "destructorn" );
  38. }
  39. int var1;
  40. string str;
  41. };
  42.  
  43. int main()
  44. {
  45. vector< MyClass1 > testArr;
  46.  
  47. MyClass1 gr1;
  48.  
  49. gr1.var1 = 111;
  50. testArr.push_back( gr1 );
  51.  
  52. gr1.var1 = 122;
  53. testArr.push_back( gr1 );
  54.  
  55. printf( "testArr.at( 1 ).var1 = %in", testArr.at( 1 ).var1 );
  56.  
  57. return 0;
  58. }
  59.  
  60. constructor
  61. destructor
  62. testArr.at( 1 ).var1 = 122
  63. destructor
  64. destructor
  65. destructor
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement