Click here to Skip to main content
15,913,836 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
Question[SOS]Winsock in ATL Dll [SOS] Pin
Eytukan26-Sep-06 23:17
Eytukan26-Sep-06 23:17 
AnswerRe: [SOS]Winsock in ATL Dll [SOS] Pin
led mike28-Sep-06 5:39
led mike28-Sep-06 5:39 
GeneralRe: [SOS]Winsock in ATL Dll [SOS] Pin
Eytukan28-Sep-06 6:32
Eytukan28-Sep-06 6:32 
GeneralRe: [SOS]Winsock in ATL Dll [SOS] Pin
led mike28-Sep-06 6:52
led mike28-Sep-06 6:52 
GeneralRe: [SOS]Winsock in ATL Dll [SOS] Pin
Eytukan28-Sep-06 7:51
Eytukan28-Sep-06 7:51 
AnswerRe: [SOS]Winsock in ATL Dll [SOS] Pin
Eytukan12-Oct-06 18:24
Eytukan12-Oct-06 18:24 
QuestionATL,WTL time object in debug and release config Pin
Samy_Ibraheem_Mo26-Sep-06 7:20
Samy_Ibraheem_Mo26-Sep-06 7:20 
GeneralFunction object destructor called multiple times in std::for_each loop Pin
Rob Caldecott26-Sep-06 7:02
Rob Caldecott26-Sep-06 7:02 
OK, I must of missed something here, but when I use a function object in a std::for_each loop, the constructor is called once (as expected), but the destructor is called multiple times! Can someone explain why this happens, and, more importantly, how I can have the destructor called just once. For example:

#include <algorithm>
#include <vector>
#include <iostream>

struct function_object
{
	function_object()
	{
		std::cout << "function_object : " << this << std::endl;
	}

	~function_object()
	{
		std::cout << "~function_object : " << this << std::endl;
	}

	void operator()(int n) const
	{
		std::cout << n << std::endl;
	}
};

int _tmain(int argc, _TCHAR* argv[])
{
	std::vector<int> v;
	v.push_back(1);
	v.push_back(2);
	std::for_each(v.begin(), v.end(), function_object());
	return 0;
}


Now, when I run the above app it seems that multiple copies of the function_object struct are created, as the destructor trace code shows different pointers. However, as only one constructor is being called, I am a little confused. The output looks like this:

function_object : 0013FE4B
1
2
~function_object : 0013FE00
~function_object : 0013FE6F
~function_object : 0013FE4B


Any ideas on how to avoid this would be welcome.



Kicking squealing Gucci little piggy.

GeneralA solution, of sorts Pin
Rob Caldecott26-Sep-06 7:21
Rob Caldecott26-Sep-06 7:21 
GeneralRe: Function object destructor called multiple times in std::for_each loop Pin
Zac Howland26-Sep-06 8:25
Zac Howland26-Sep-06 8:25 
GeneralRe: Function object destructor called multiple times in std::for_each loop Pin
Rob Caldecott26-Sep-06 8:30
Rob Caldecott26-Sep-06 8:30 
GeneralRe: Function object destructor called multiple times in std::for_each loop Pin
Zac Howland26-Sep-06 8:43
Zac Howland26-Sep-06 8:43 
GeneralRe: Function object destructor called multiple times in std::for_each loop Pin
Rob Caldecott26-Sep-06 10:17
Rob Caldecott26-Sep-06 10:17 
GeneralRe: Function object destructor called multiple times in std::for_each loop Pin
Zac Howland26-Sep-06 10:59
Zac Howland26-Sep-06 10:59 
Questionwhat is WTL ? Pin
Sakthiu26-Sep-06 3:36
Sakthiu26-Sep-06 3:36 
AnswerRe: what is WTL ? Pin
led mike26-Sep-06 7:30
led mike26-Sep-06 7:30 
AnswerRe: what is WTL ? Pin
Michael Dunn2-Oct-06 7:35
sitebuilderMichael Dunn2-Oct-06 7:35 
GeneralRe: what is WTL ? Pin
Steve S27-Sep-06 1:22
Steve S27-Sep-06 1:22 
QuestionBHO cpu usage is too high Pin
daheitou26-Sep-06 3:10
daheitou26-Sep-06 3:10 
QuestionWTL code wrappers for Scintilla Pin
Igor Vigdorchik25-Sep-06 8:29
Igor Vigdorchik25-Sep-06 8:29 
AnswerRe: WTL code wrappers for Scintilla Pin
Alain Rist25-Sep-06 12:43
Alain Rist25-Sep-06 12:43 
GeneralRe: WTL code wrappers for Scintilla Pin
Igor Vigdorchik25-Sep-06 14:57
Igor Vigdorchik25-Sep-06 14:57 
Questionregister an attributed ATL7 com dll file [modified] Pin
Samy_Ibraheem_Mo24-Sep-06 10:04
Samy_Ibraheem_Mo24-Sep-06 10:04 
AnswerRe: register an attributed ATL7 com dll file Pin
Samy_Ibraheem_Mo24-Sep-06 17:13
Samy_Ibraheem_Mo24-Sep-06 17:13 
AnswerRe: register an attributed ATL7 com dll file Pin
User 21559724-Sep-06 22:31
User 21559724-Sep-06 22:31 

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.