C
clinisbut
I'm trying to understand what's wrong with this:
void getAllData( std::vector<unsigned char> &char_array )
{
char_array.clear();
char_array.reserve( 11 );
char_array[0] = 'A'; //<----No error compilation, but no
effect!!
}
and then I call this function:
std::vector<unsigned char> char_array;
getAllData( char_array );
But if I do this:
void getAllData( std::vector<unsigned char> &char_array )
{
char_array.clear();
char_array.reserve( 11 );
char_array.push_back('A'); //Works
}
It works good, but when I try to read some element with [] operator
doesn't works...
What's the correct way to deal with a vector inside a function???
PD: What's the diference between using & and * in function header's
parameter list?
void getAllData( std::vector<unsigned char> &char_array )
{
char_array.clear();
char_array.reserve( 11 );
char_array[0] = 'A'; //<----No error compilation, but no
effect!!
}
and then I call this function:
std::vector<unsigned char> char_array;
getAllData( char_array );
But if I do this:
void getAllData( std::vector<unsigned char> &char_array )
{
char_array.clear();
char_array.reserve( 11 );
char_array.push_back('A'); //Works
}
It works good, but when I try to read some element with [] operator
doesn't works...
What's the correct way to deal with a vector inside a function???
PD: What's the diference between using & and * in function header's
parameter list?