I want to write some unit tests of a library I'm writing
I have a class which looks like this one :
class A
{
public:
A(B* pB)
// construction details, involves my library
// but ultimately there is a new being done ,)
B* m_pB;
};
I'd like to check that the pointer m_pB is actually initialized, so I did something along these lines :
A* p = // creation of this object involves my library
BOOST_REQUIRE( p->m_pB != NULL );
but it happens g++ does not zero-initialize the memory, so the value of p->m_pB
is just plain random. Is there a way to force g++ to zero initialize this memory for me when I new
the object?
I believe Visual Studio does something similar with specific codes dependeing on where the memory is allocated.
edit: I can think of 2 backup solutions right now: using a smart pointer, or writing a new operator ...