A
A
let's say I have:
struct TWhatever
{
int MyInt;
bool MyBool;
}
Now I have already preallocated memory to where pWhatever points so:
TWhatever* pWhatever;
// Memory is already preallocated so the below lines work properly
pWhatever->MyInt = 1;
pWhatever->MyBool = false;
And now I also have vector:
std::vector<TWhatever> MyVect;
MyVect.pushBack(TWhatever());
MyVect[0].MyInt = 1;
MyVect[0].MyBool = false;
And now the question finally - all I want is to copy data from vector to
memory that pWhatever points to.
So I tried:
pWhatever = &MyVect[0]; // doesn't seem to work
But this worked:
pWhatever->MyInt = MyVect[0].MyInt; // works
pWhatever->MyBool = MyVect[0].MyBool; // also works
The question - can I do it somehow simpler than the last example? The
problem is not in last 2 lines but there are 30 or so lines for each
initialization so something simpler would be much more readable in code.
struct TWhatever
{
int MyInt;
bool MyBool;
}
Now I have already preallocated memory to where pWhatever points so:
TWhatever* pWhatever;
// Memory is already preallocated so the below lines work properly
pWhatever->MyInt = 1;
pWhatever->MyBool = false;
And now I also have vector:
std::vector<TWhatever> MyVect;
MyVect.pushBack(TWhatever());
MyVect[0].MyInt = 1;
MyVect[0].MyBool = false;
And now the question finally - all I want is to copy data from vector to
memory that pWhatever points to.
So I tried:
pWhatever = &MyVect[0]; // doesn't seem to work
But this worked:
pWhatever->MyInt = MyVect[0].MyInt; // works
pWhatever->MyBool = MyVect[0].MyBool; // also works
The question - can I do it somehow simpler than the last example? The
problem is not in last 2 lines but there are 30 or so lines for each
initialization so something simpler would be much more readable in code.