Click here to Skip to main content
15,891,864 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Why fclose is so slow and what is its internal implematation. Pin
Luc Pattyn29-Dec-08 3:27
sitebuilderLuc Pattyn29-Dec-08 3:27 
QuestionCHM version of the C++ FAQ Lite Options There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic. There was an error processing your request. Please try again. Standa Pin
Lawand27-Dec-08 8:40
Lawand27-Dec-08 8:40 
AnswerNO advertising, please Pin
CPallini27-Dec-08 9:03
mveCPallini27-Dec-08 9:03 
GeneralRe: NO advertising, please Pin
Lawand27-Dec-08 9:15
Lawand27-Dec-08 9:15 
GeneralRe: NO advertising, please Pin
CPallini27-Dec-08 10:01
mveCPallini27-Dec-08 10:01 
GeneralRe: NO advertising, please Pin
Rajesh R Subramanian28-Dec-08 4:57
professionalRajesh R Subramanian28-Dec-08 4:57 
QuestionFailed to Launch Help Pin
Ali Tavakol27-Dec-08 3:57
Ali Tavakol27-Dec-08 3:57 
Questionauto_ptr - passing to functions and best practices Pin
Christian Flutcher27-Dec-08 2:53
Christian Flutcher27-Dec-08 2:53 
void anotherMethod(auto_ptr<Foo> foo)
{
	cout << "Taken ownership. " << foo->getAString() << endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
	auto_ptr<Foo> foo(new Foo);
	cout << foo->getAString() << endl;
	anotherMethod(foo);
	// this will throw error as the pointer is deleted
	cout << "From main again " << foo->getAString();
	cout << "Ending main" << endl;
	return 0;
}
In the avove code, I am trying to pass the auto_ptr to another function. But doing this will make the another function take ownership and the underlying pointer will be deleted when another functions scope ends. So I am unable to access it in the main method again. To workaround this issue, I changed the code like
void anotherMethod(const auto_ptr<Foo>& foo)
{
	cout << "Taken ownership. " << foo->getAString() << endl;
}
The below code will also work
void anotherMethod(Foo* foo)
{
	cout << "Taken ownership. " << foo->getAString() << endl;
}

// in main I called like
auto_ptr<Foo> foo(new Foo);
anotherMethod(foo.get());
I am wondering which one is the best approach? Can anyone help?

Also is it a good practice to use auto_ptr over normal pointers and is it always guranteed the cleanup?
AnswerRe: auto_ptr - passing to functions and best practices Pin
Chris Losinger27-Dec-08 5:22
professionalChris Losinger27-Dec-08 5:22 
GeneralRe: auto_ptr - passing to functions and best practices Pin
Christian Flutcher27-Dec-08 5:58
Christian Flutcher27-Dec-08 5:58 
GeneralRe: auto_ptr - passing to functions and best practices Pin
Chris Losinger27-Dec-08 6:17
professionalChris Losinger27-Dec-08 6:17 
GeneralRe: auto_ptr - passing to functions and best practices Pin
Christian Flutcher27-Dec-08 6:26
Christian Flutcher27-Dec-08 6:26 
GeneralRe: auto_ptr - passing to functions and best practices Pin
Mark Salsbery27-Dec-08 7:07
Mark Salsbery27-Dec-08 7:07 
GeneralRe: auto_ptr - passing to functions and best practices Pin
Christian Flutcher27-Dec-08 16:27
Christian Flutcher27-Dec-08 16:27 
GeneralRe: auto_ptr - passing to functions and best practices Pin
Mark Salsbery28-Dec-08 4:31
Mark Salsbery28-Dec-08 4:31 
Questionbuttons are hidden by picture control Pin
VCProgrammer27-Dec-08 1:26
VCProgrammer27-Dec-08 1:26 
AnswerRe: buttons are hidden by picture control Pin
Richard Andrew x6427-Dec-08 1:52
professionalRichard Andrew x6427-Dec-08 1:52 
GeneralRe: buttons are hidden by picture control Pin
VCProgrammer27-Dec-08 1:57
VCProgrammer27-Dec-08 1:57 
GeneralRe: buttons are hidden by picture control Pin
Richard Andrew x6427-Dec-08 1:59
professionalRichard Andrew x6427-Dec-08 1:59 
QuestionRe: buttons are hidden by picture control Pin
CPallini27-Dec-08 4:57
mveCPallini27-Dec-08 4:57 
GeneralRe: buttons are hidden by picture control Pin
Luc Pattyn27-Dec-08 5:47
sitebuilderLuc Pattyn27-Dec-08 5:47 
JokeRe: buttons are hidden by picture control Pin
CPallini27-Dec-08 7:03
mveCPallini27-Dec-08 7:03 
Generalare you being served? Pin
Luc Pattyn27-Dec-08 8:36
sitebuilderLuc Pattyn27-Dec-08 8:36 
QuestionHow can SpeedUp Build Process? Pin
Le@rner26-Dec-08 22:45
Le@rner26-Dec-08 22:45 
AnswerRe: How can SpeedUp Build Process? Pin
Jijo.Raj27-Dec-08 0:28
Jijo.Raj27-Dec-08 0:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.