Paul <
peps...@gmail.com> wrote:
> I suspect that there's a problem below with using
> the temporary variable RandomGen(Constants::testRandomNums, Constants::testProbabilities) as a parameter for the TestNextNum
> constructor.
>
> Is this a problem?
It depends on what exactly you are doing with that reference.
If you are, for example, just using the object pointed by that reference
within that constructor implementation and nothing else, then there's no
problem (because the object will exist for as long as the constructor is
being executed). If you are initializing a member variable of TestNextNum
(by calling its copy or move constructor, or possibly the copy or move
assignment operator) with that parameter, there's also no problem (because
the parameter itself won't be used anymore after that).
If you are assuming the lifetime of the object pointed to by the rerence
is longer than the duration of the constructor, then you would have a
problem.