c++ - std::bad_alloc assigning a pointer from address of a reference -
for whatever reason, ended code looked this
typedef std::vector<double> vector; void f(vector const& v) { vector const* p; p = &v; }
this throws bad_alloc
exception @ point of assignment. why? matter f
called on non-cast vector? c++03 compiled on gcc 4.1.
** edit ** inside code running inside google mock see exception. tried tear code out , compile separately , worked fine. looking further
** further edit ** problem assignment happened in last line of constructor of object member of object. next object in initializer list of parent object exception coming from, gdb made happening on last line of previous object's constructor assignment taking place. downvotes remind me how misguided question was.
there no possible way code can raise std::bad_alloc
exception (or other exception, matter), since doing assigning pointer value pointer variable. std::bad_alloc
raised new
, new[]
operators when memory allocation fails, , there no such memory allocation being performed in code.
Comments
Post a Comment