Connecting Tech Pros Worldwide Forums | Help | Site Map

auto_ptr init question

kvnil
Guest
 
Posts: n/a
#1: Mar 18 '08
Any idea why would the following executable would crash (on Windows, VS2005
compiler)?

#include <memory>

struct C{};

int main(int argc, char** argv[])
{
std::auto_ptr<CpC /*(new C())*/;
pC = new C();
return 0;
}

If the "new" part is move into the auto_ptr ctor (the commented part), the
exe terminates fine. Otherwise, it goes postal.

-- kvnil



Ian Collins
Guest
 
Posts: n/a
#2: Mar 18 '08

re: auto_ptr init question


kvnil wrote:
Quote:
Any idea why would the following executable would crash (on Windows,
VS2005 compiler)?
>
#include <memory>
>
struct C{};
>
int main(int argc, char** argv[])
{
std::auto_ptr<CpC /*(new C())*/;
pC = new C();
This shouldn't compile.
Quote:
return 0;
}
>
If the "new" part is move into the auto_ptr ctor (the commented part),
the exe terminates fine. Otherwise, it goes postal.
>
postal as in slow??
--
Ian Collins.
Barry
Guest
 
Posts: n/a
#3: Mar 18 '08

re: auto_ptr init question


On 3月18日, 下午6时02分, kvnil <kv...@mail.ruwrote:
Quote:
Any idea why would the following executable would crash (on Windows, VS2005
compiler)?
>
#include <memory>
>
struct C{};
>
int main(int argc, char** argv[])
{
std::auto_ptr<CpC /*(new C())*/;
pC = new C();
return 0;
>
}
>
If the "new" part is move into the auto_ptr ctor (the commented part), the
exe terminates fine. Otherwise, it goes postal.
>
As marked by else threads, the code shouldn't compile against standard
conformed
compiler&library.

the problem here is that VC2005 use void other than T for
auto_ptr_ref.
VC9 has already fixed this.

try debug your code to see what's going on inside.


Closed Thread


Similar C / C++ bytes