What you are trying to do is bad in general. There are some main points to it:
If you are encapsulating vector
in class, you can still operate on it normally from the outside if it's public.
WavFile WF;
void* Ptr = WF.SoundData.data();
// void* Ptr = &WF.SoundData[0]; - C++03
You can also wrap some of the calls to the vector, .resize()
for example:
void WavFile::resize(vector::size_type new_size) {
SoundData.resize(new_size);
}
void* WavFile::getRawPtr () {
return SoundData.data();
// return (&SoundData[0]); - C++03
}
If you are using std::vector
, you should also use corresponding C++ read functions on it. Treating vector
as a memory array is valid, but there are better ways to use it, fstream
for example.
If you are encapsulating vector
(or any std
container in general), don't return it by value! It will cause all of the elements to be copied. Instead, return a const-reference to container, or, even better, range.