That is a known and documented feature. We are being called from R via the interface
SEXP somefunction(SEXP a, SEXP b, ...)
so a pointer is being passed and changes to Q
affect the outer object. That is a good thing as it makes the calls very fast -- no copies.
If you want distinct instances, use the clone()
method as in
NumericMatrix Q = clone(Qin);