Wednesday, 7 August 2013

std::bad_alloc assigning a pointer from address of a reference

std::bad_alloc assigning a pointer from address of a reference

For whatever reason, I ended up with code that looked like this
typedef std::vector<double> Vector;
void f(Vector const& v) {
Vector const* p;
p = &v;
}
This throws a bad_alloc exception at the point of assignment. Why? Does it
matter that f was called on a non-cast vector? This is C++03 compiled on
gcc 4.1.
** Edit ** This is inside some code running inside google mock that I see
the exception. I tried to tear the code out and compile it separately and
it worked fine. Looking further

No comments:

Post a Comment