Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static vector<int> myVector(4,100);
- int main() {
- // Here I have a vector of size 4 with all the entries equal to 100
- }
- #include <vector>
- static std::vector<int> myVector(4,100);
- bool init()
- {
- myVector[0] = 42;
- return true;
- }
- bool initresult = init();
- int main()
- {
- ;
- }
- static int init[] = { 1, 2, 3 };
- static vector<int> vi(init, init + sizeof init / sizeof init[ 0 ]);
- struct MyInitializer {
- MyInitializer() {
- myVector[0]=100;
- //...
- }
- } myInitializer; // This object gets constructed before main()
- std::vector<int> init()
- {
- ...
- }
- static std::vector<int> myvec = init()
- std::vector<int> bottles_of_beer_on_the_wall = {100, 99, 98, 97};
- class A {
- public:
- A() {
- // ... code that might throw an exception
- }
- };
- std::Vector<A> v(5, A()); // May throw an exception here not caught by main
- int main () {
- try {
- // Exception for 'v' not handled here.
- }
- catch (...) {
- }
- }
- std::Vector<A> init (); // Returns a vector appropriately initialized
- std::vector<A> & getV () {
- static std::vector<A> cache = init();
- return cache;
- }
- int main () {
- try {
- getV().at[0]; // First call to getV - so initialization occurs here!
- }
- catch (...) {
- }
- }
- class SpecialVector
- {
- public:
- SpecialVector()
- {
- myVector[0] = 1;
- myVector[1] = 4;
- // etc.
- }
- const vector<int> & GetVector() const
- {
- return myVector;
- }
- private:
- vector<int> myVector;
- };
- static SpecialVector SpVec;
- int main() {
- }
Add Comment
Please, Sign In to add comment