December 2001
Intermediate to advanced
304 pages
6h 25m
English
Difficulty: 5
Oil and water just don't mix. Do pointers and standard containers mix any better?
Consider the following code:
vector<char> v; // ... populate v ... char* p = &v[0]; // ... do something with *p ...
Is this code valid? Whether it's valid or not, how could it be improved?
Now consider the following code:
template<typename T>
void f( T& t )
{
typename T::value_type* p1 = &t[0];
typename T::value_type* p2 = &*t.begin();
// ... do something with *p1 and *p2 ...
}
Is this code valid? Discuss.
Little Stanislaus watched his mother as she rummaged busily in the refrigerator. ...
Read now
Unlock full access