Connecting Tech Pros Worldwide Help | Site Map

auto_ptr init question

  #1  
Old March 18th, 2008, 11:15 AM
kvnil
Guest
 
Posts: n/a
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


  #2  
Old March 18th, 2008, 11:25 AM
Ian Collins
Guest
 
Posts: n/a

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.
  #3  
Old March 18th, 2008, 01:55 PM
Barry
Guest
 
Posts: n/a

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 Threads
Thread Thread Starter Forum Replies Last Post
beginner question Lloyd Dupont answers 10 November 17th, 2005 05:25 PM
Quick question on smart pointers Susan Baker answers 27 July 23rd, 2005 07:16 AM