[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

auto_ptr

Posted on 2011-03-10
6
Medium Priority
?
407 Views
Last Modified: 2012-05-11
Is there any difference betwwen the following declaration

std::string *myStr

str::auto_ptr<std::string> myStr;

Do I have to delete/destory any of these objects or does the compile takes care of it?
0
Comment
Question by:learningunix
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 1000 total points
ID: 35099768
You didn't actually allocate any memory in either those statements, so there's also no need to de-allocate any memory.

However, assuming that you meant these instead :

        std::string* myStr = new std::string();
        std::auto_ptr<std::string> myStr(new std::string());

Then the former would require you to de-allocate the allocated memory yourself (using delete myStr), but the latter will clean up the memory for you automatically, as soon as myStr goes out of scope.

Read more on std::auto_ptr here :

        http://www.cplusplus.com/reference/std/memory/auto_ptr/
0
 
LVL 11

Expert Comment

by:Deepu Abraham
ID: 35105896
0
 
LVL 35

Expert Comment

by:sarabande
ID: 35107392
you might not find a reason for using a std::string pointer at all. std::string has dynamic management of internal buffer and reference counting. you won't get a benefit when using pointers rather than objects.

Sara
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 53

Expert Comment

by:Infinity08
ID: 35107436
Heh, I don't think that's the point of the question, Sara ;)
0
 
LVL 35

Expert Comment

by:sarabande
ID: 35107509
sorry, i always overact when i see pointers :)

Sara
0
 

Author Closing Comment

by:learningunix
ID: 35130688
got it
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question