From the course: C++ Design Patterns: Creational
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Running the Singleton pattern - Visual Studio Express Tutorial
From the course: C++ Design Patterns: Creational
Running the Singleton pattern
- [Instructor] Let's pick up where we left off in the last video. To show how a singleton pattern all works, I've opened 07_03_Singleton. I'm going to put a break point here at line 36 and start writing the application by pressing F5. Here, we've stopped at line 36 and the program is about to access the leader instance for the first time. I step into this call by pressing F11, and we end up at line 18 where the getInstance method is going to get the instance of the singleton. I press F10 to go to the next line, where it checks to see if an instance already exists yet. Since it doesn't exist yet, when I press F10, a new instance is created on line 21. If I hit F10 one more time, notice on the console, we see the phrase, new leader elected, which means the singleton was created. Here at line 23, we'll return this instance. I'll keep pressing F10 to continue on until we end up back in the main. If I step again by…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.