title: "Cannot" move pointer
body: <p>In my code I have:  </p>
  
  <pre><code>template&lt;class Ui_Dialog&gt;
  QDialog* Base_Dialog&lt;Ui_Dialog&gt;::set_caller(QDialog *new_caller)
  {
   QDialog* old_caller = caller_;
  
   caller_ = new_caller;//Here I'm trying to set this to new caller
  
   return old_caller;
  } 
  </code></pre>
  
  <p>but after setting the caller to new caller and exiting from this fnc, when I call caller I'm still getting the old caller instead of new one, as if no changes were made. Why?<br>
  EDIT:  </p>
  
  <pre><code>//caller is defined in a following way:  
      class Main_Dialog : public Base_Dialog&lt;Ui::Main_Dialog&gt; {};  
  </code></pre>
  
  <p>EDIT 2:<br>
  The interesting thing is that if instead of public Base_Dialog I alter Base_Dialog to non-template and define Main_Dialog as:<br>
          <code>class Main_Dialog : public Base_Dialog, private Ui::Main_Dialog {};</code><br>
  Then it works as intended. Why?!<br>
  EDIT 3:  </p>
  
  <pre><code>class Main_Dialog;
      template&lt;class Ui_Dialog&gt;
      class Base_Dialog : public QDialog, protected Ui_Dialog
      {
         // Q_OBJECT //no signals/slots
      protected:
          Main_Dialog* main_dlg_;
          QDialog* caller_;
  
      public:
          Base_Dialog(Main_Dialog *main_dlg, QDialog *caller, QWidget *parent = nullptr);
          QDialog* set_caller(QDialog *);
          QDialog* clear_caller();
          Main_Dialog* clear_main_dlg();
  
      };
  
      /*----------------*/
  
          #include "Main_Dialog.hpp"
          template&lt;class Ui_Dialog&gt;
          Base_Dialog&lt;Ui_Dialog&gt;::Base_Dialog(Main_Dialog *main_dlg,QDialog *caller, QWidget *parent):
              QDialog(parent),
              main_dlg_(main_dlg),
              caller_(caller)
          {
              //setupUi(this);
          }
  
  
          #include &lt;QtDebug&gt;
          template&lt;class Ui_Dialog&gt;
          QDialog* Base_Dialog&lt;Ui_Dialog&gt;::set_caller(QDialog *new_caller)
          {
           QDialog* old_caller = caller_;
  
           caller_ = new_caller;
  
           return old_caller;
          }  
  #include "_1Dialog.hpp"
  #include "_2Dialog.hpp"
  class Main_Dialog : public Base_Dialog&lt;Ui::Main_Dialog&gt;
  {
      Q_OBJECT
      QSet&lt;QDialog*&gt;* dialogs_;
  private:
      template&lt;class Dialog,class Caller&gt;
      bool already_created_(Caller*&amp;, QDialog*&amp; already_exists)const;
  
      template&lt;class Dialog,class Caller, class Parent&gt;
      QDialog* create_(Caller*,Parent*);
  
      /*template&lt;class Dialog&gt;
      void show_();*/
  
     /* template&lt;class Dialog,class Caller&gt;
      QDialog* find_(Caller*)const;*/
  public:
      explicit Main_Dialog(QWidget *parent = 0);
      template&lt;class Dialog,class Caller&gt;
      QDialog* get_dialog(Caller*&amp; caller);
  public slots:
      void _1clicked();
      void _2clicked();
  };
  
  template&lt;class Dialog,class Caller&gt;
  bool Main_Dialog::already_created_(Caller*&amp; caller,QDialog*&amp; already_exists)const
  {/*the already_exists is introduced here in order to remove repetions of code and
     searching*/
      auto beg = dialogs_-&gt;begin();
      auto end = dialogs_-&gt;end();
      while(beg != end)
      {
          if(dynamic_cast&lt;Dialog*&gt;(*beg))
          {
              already_exists = *beg;
              static_cast&lt;Base_Dialog*&gt;(already_exists)-&gt;set_caller(caller);
              return true;
          }
  
          ++beg;
      }
      return false;
  }
  
  
  
      template&lt;class Dialog,class Caller, class Parent&gt;
      QDialog* Main_Dialog::create_(Caller *caller, Parent *parent)
      {
          return (*dialogs_-&gt;insert(new Dialog(this,caller,parent)));
      }
  
      template&lt;class Dialog,class Caller&gt;
      QDialog* Main_Dialog::get_dialog(Caller *&amp;caller)
      {
          QDialog* already_exists = nullptr;
          if (already_created_&lt;Dialog&gt;(caller,already_exists))
          {
              return already_exists;
          }
          else
          {
              return create_&lt;Dialog&gt;(caller,this);
          }  
      #include "Base_Dialog.hpp"
      #include "ui__1Dialog.h"
  
      class Main_Dialog;
      class _1Dialog : public Base_Dialog&lt;Ui::_1Dialog&gt;
      {
          Q_OBJECT
      public:
          explicit _1Dialog(Main_Dialog* main_dlg, QDialog*caller, QWidget *parent = 0);
  
      private slots:
          void _2clicked();
          void caller_clicked();
          void main_clicked();
      };
  
      #endif // _1DIALOG_HPP
      #include "_1Dialog.hpp"
      #include "_2Dialog.hpp"
      #include "Main_Dialog.hpp"
      _1Dialog::_1Dialog(Main_Dialog* main_dlg, QDialog*caller, QWidget *parent) :
          Base_Dialog(main_dlg,caller,parent)
      {
          setupUi(this);
      }
  
      void _1Dialog::_2clicked()
      {
          this-&gt;hide();
          main_dlg_-&gt;get_dialog&lt;_2Dialog&gt;(this)-&gt;show();
      }
  
  
      void _1Dialog::caller_clicked()
      {
          this-&gt;hide();
          caller_-&gt;show();
      }
  
      void _1Dialog::main_clicked()
      {
          this-&gt;hide();
          main_dlg_-&gt;show();
      }
  
      }
      #endif // MAIN_DIALOG_HPP
  </code></pre>