Given a class of the form
and assuming there is _no_ other data in the class, do the language specs guarantee the following snippet is valid?Code:class DataVector
{
public:
DataVector(int i, int j, int k){
_vals[0] = i;
_vals[1] = j;
_vals[2] = k;
}
int* data(void){return _vals;}
private:
int _vals[3];
}
Code:std::vector<DataVector> myVec(2);
myVec[0] = DataVector(0,1,2);
myVec[1] = DataVector(3,4,5);
int* dP = myVec[0].data();
std::cout<<dP[0]<<" "<<dP[1]<<" "<<dP[2]<<" "<<dP[3]<<" "<<dP[4]<<<<" " <<dP[5];
//should output 0 1 2 3 4 5
The reason I'm implementing the code this way is that I may need to pad the 3 dimensional vector to 16 bytes with an extra element depending on some external factors that are currently out of my control. If there are better ways of doing this, I'm open to suggestions.