Connecting Tech Pros Worldwide Help | Site Map

auto_ptr init question

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 18th, 2008, 10:15 AM
kvnil
Guest
 
Posts: n/a
Default auto_ptr init question

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, 10:25 AM
Ian Collins
Guest
 
Posts: n/a
Default 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, 12:55 PM
Barry
Guest
 
Posts: n/a
Default 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.


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.