<p>According to the <a href="http://stackoverflow.com/questions/5058349/is-it-safe-to-use-the-this-pointer-in-an-initialization-list">answer of stackoverflow</a>, it should be safe to that as long as we do not access the member haven't construct yet(including virtual member function, but mlpack do not use any virtual, so I think this would not be an issue). </p>
<p>What I mean is, change the reference to pointer as following</p>
<pre><code>RMSPROP(DecomposableFunctionType* function,
const double lr = 0.01,
const double alpha = 0.99,
const double eps = 1e-8) :
function(function),
lr(lr),
alpha(alpha),
eps(eps)
</code></pre>
<p>So we could construct it as </p>
<pre><code>SparseBiasLayer(const size_t outSize,
const size_t batchSize,
WeightInitRule weightInitRule = WeightInitRule()) :
outSize(outSize),
batchSize(batchSize),
optimizer(new OptimizerType<SparseBiasLayer<OptimizerType,
WeightInitRule,
InputDataType,
OutputDataType>,
InputDataType>(this)),
ownsOptimizer(true)
</code></pre>
<p>Is this the problem you are worrying about?Or we are talking different problems?</p>
<p>ps : I forgot I open the same issue on <a href="https://github.com/mlpack/mlpack/issues/495" class="issue-link js-issue-link" data-url="https://github.com/mlpack/mlpack/issues/495" data-id="121941761" data-error-text="Failed to load issue title" data-permission-text="Issue title is private">#495</a>, rcurtin has an <a href="https://github.com/mlpack/mlpack/commit/60c81702c432014544351948c091d03deeef6985">example</a>. If you think it is ok, I would find a way to serialize it.</p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br>Reply to this email directly or <a href="https://github.com/mlpack/mlpack/issues/513#issuecomment-177752093">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFNK27CwzNlngra-wzTljclFCKklmks5pfs_hgaJpZM4HQHGn.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
<link itemprop="url" href="https://github.com/mlpack/mlpack/issues/513#issuecomment-177752093"></link>
<meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>