Guest User

Untitled

a guest
Jun 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. static vector<int> myVector(4,100);
  2.  
  3. int main() {
  4.  
  5. // Here I have a vector of size 4 with all the entries equal to 100
  6.  
  7. }
  8.  
  9. #include <vector>
  10. static std::vector<int> myVector(4,100);
  11.  
  12. bool init()
  13. {
  14. myVector[0] = 42;
  15. return true;
  16. }
  17.  
  18. bool initresult = init();
  19.  
  20. int main()
  21. {
  22. ;
  23. }
  24.  
  25. static int init[] = { 1, 2, 3 };
  26. static vector<int> vi(init, init + sizeof init / sizeof init[ 0 ]);
  27.  
  28. struct MyInitializer {
  29. MyInitializer() {
  30. myVector[0]=100;
  31. //...
  32. }
  33. } myInitializer; // This object gets constructed before main()
  34.  
  35. std::vector<int> init()
  36. {
  37. ...
  38. }
  39.  
  40. static std::vector<int> myvec = init()
  41.  
  42. std::vector<int> bottles_of_beer_on_the_wall = {100, 99, 98, 97};
  43.  
  44. class A {
  45. public:
  46. A() {
  47. // ... code that might throw an exception
  48. }
  49. };
  50.  
  51. std::Vector<A> v(5, A()); // May throw an exception here not caught by main
  52.  
  53. int main () {
  54. try {
  55. // Exception for 'v' not handled here.
  56. }
  57. catch (...) {
  58. }
  59. }
  60.  
  61. std::Vector<A> init (); // Returns a vector appropriately initialized
  62.  
  63. std::vector<A> & getV () {
  64. static std::vector<A> cache = init();
  65. return cache;
  66. }
  67.  
  68. int main () {
  69. try {
  70. getV().at[0]; // First call to getV - so initialization occurs here!
  71. }
  72. catch (...) {
  73. }
  74. }
  75.  
  76. class SpecialVector
  77. {
  78. public:
  79. SpecialVector()
  80. {
  81. myVector[0] = 1;
  82. myVector[1] = 4;
  83. // etc.
  84. }
  85. const vector<int> & GetVector() const
  86. {
  87. return myVector;
  88. }
  89. private:
  90. vector<int> myVector;
  91. };
  92. static SpecialVector SpVec;
  93.  
  94. int main() {
  95. }
Add Comment
Please, Sign In to add comment