free hit counter

Monday, January 09, 2006

delayed initialization of std::auto_ptr<>


std::auto_ptr p(new int(42)) //ok
std::auto_ptr q;
std::auto_ptr r;

q = std::auto_ptr(new int(23)); //ok
r = new int(23); //BAD BAD

Because the constructor for auto_prt is explicit the inititialization of r will not do what you expect and should never be used. Unfortunatly, it does compile though...

0 Comments:

Post a Comment

<< Home