c++ pass by reference safely and compile time checking on size <pre><code>SpiDeviceDriver::SPI_Error SpiDeviceDriver::SPI_ReadBytes( quint32 size_, QVector&lt;quint8&gt;&amp; rxData_ ) { //Get data and fill QVector&lt;quint8&gt; with data } </code></pre> <p>I'm trying to call a class function (from another class) and pass in a <code>QVector</code>, then fill it with data.</p> <ol> <li><p>I prefer to just pass in the <code>QVector</code> alone (without the <code>quint32</code> size parameter) and then figure out the size from that and fill it with data according to its size. However, if the passed in <code>QVector</code> is size 0, I'd either have to assume it is meant to be size 1, creating a new spot for the data, or throw/handle the error at run-time, which i'd rather not do. Compile time error checking would be much better. Is there a better way to do this?</p></li> <li><p>I guess you could pass in a <code>quint32 size_</code> parameter, then forget what the size of the <code>QVector</code> is and force the resizing to be that size. This seems awkward as well</p></li> </ol> <p><strong>Note:</strong> I've been instructed by my boss to make every function return an <code>enum</code> error code, so just using a <code>size_</code> and creating a vector, then returning that data is not an option.</p>