Note that there are some explanatory texts on larger screens.

plurals
  1. POdelayed initialization?
    primarykey
    data
    text
    <p>could somebody please explain why this happens? I have written the following:</p> <p>1) a WindowManager class which is implemented as a singleton and has an <code>Instance()</code> method, defined like so:</p> <pre><code>static WindowManager * instance_; //... WindowManager * WindowManager::instance_ = 0; WindowManager &amp; WindowManager::Instance() { if (!instance_) instance_ = new WindowManager(); return *instance_; } </code></pre> <p>2) a <code>WindowManager::createWindow</code> method that returns a reference to a newly created window, defined like so:</p> <pre><code>Window &amp; WindowManager::createWindow() { windows_.push_back(Window()); return windows_.at(windows_.size() - 1); } </code></pre> <p>3) a <code>Window::print</code> method that prints a message inside the window</p> <p>In my main program, I have written the following:</p> <pre><code>ui::Window &amp; win1 = ui::WindowManager::Instance().createWindow(); ui::Window &amp; win2 = ui::WindowManager::Instance().createWindow(); win1.print("First window"); win2.print("Second window"); </code></pre> <p>This does not work! Only the second call to <code>print</code> is executed (for <code>win2</code>). However, if I change the order, like so:</p> <pre><code>ui::Window &amp; win1 = ui::WindowManager::Instance().createWindow(); win1.print("First window"); ui::Window &amp; win2 = ui::WindowManager::Instance().createWindow(); win2.print("Second window"); </code></pre> <p>then everything works as expected. If anybody could shed some light on this situation, any help would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload