Click here to Skip to main content
15,919,132 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Issue with GetProcAddress Pin
Daniel Gow11-Dec-04 13:04
Daniel Gow11-Dec-04 13:04 
QuestionNewbie Ques: How to get all Files and Directorys in a Directory? Pin
RedDragon2k8-Dec-04 5:28
RedDragon2k8-Dec-04 5:28 
AnswerRe: Newbie Ques: How to get all Files and Directorys in a Directory? Pin
BlackDice8-Dec-04 5:55
BlackDice8-Dec-04 5:55 
AnswerRe: Newbie Ques: How to get all Files and Directorys in a Directory? Pin
alex.barylski8-Dec-04 11:45
alex.barylski8-Dec-04 11:45 
QuestionHow to change SW_SHOWDEFAULT Pin
mcgahanfl8-Dec-04 4:50
mcgahanfl8-Dec-04 4:50 
AnswerRe: How to change SW_SHOWDEFAULT Pin
David Crow8-Dec-04 5:09
David Crow8-Dec-04 5:09 
General'Find' algorithm for vector using pointer to class object Pin
BlackDice8-Dec-04 4:06
BlackDice8-Dec-04 4:06 
GeneralRe: 'Find' algorithm for vector using pointer to class object Pin
Jack Puppy8-Dec-04 15:01
Jack Puppy8-Dec-04 15:01 
The problem here is you're comparing pointers, and not the objects they point to.

Here's the code for find algorithm:
<br />
	{	// find first matching _Val<br />
	for (; _First != _Last; ++_First)<br />
		if (*_First == _Val)<br />
			break;<br />
	return (_First);<br />
	}<br />


*_First dereferences the iterator, which gives you a pointer to a CWatchedWindow. So basically, you're doing this:

<br />
int * x = 0;<br />
<br />
// compares address of x to a value<br />
if (x == 10)<br />
<br />


whereas you want this:

<br />
int * x = 0;<br />
<br />
// compares the value of x to a value<br />
if (*x == 0)<br />
<br />


The way that I know to get around this problem is by using find_if() with a predicate.

<br />
<br />
class MatchName<br />
{<br />
   MatchName(LPCTSTR lpszName) : m_strName(lpszName)<br />
   {<br />
   }<br />
    // Function call operator<br />
    bool operator()(CWatchedWindow* window)<br />
    {<br />
        return (window->m_strName.CompareNoCase(m_strName) == 0);<br />
    }<br />
}<br />
<br />
// In your main code:<br />
<br />
iFind = find_if(blah.begin(), blah.end(), MatchName("Window Name"));<br />
<br />
if (iFind != blah.end())<br />
  AfxMessageBox("Found it");<br />
<br />


The code for find_if is as follows:

<br />
<br />
for (; _First != _Last; ++_First)<br />
		if (_Pred(*_First))<br />
			break;<br />
	return (_First);<br />


The _Pred(*_First) line triggers the function call operator defined in MatchName for each of the objects in the vector.

I think there is a way to avoid creating a class (ptr_fun? or something bizarre like that), but I'm only familar with the above method.


Suspicious | :suss: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
GeneralRe: 'Find' algorithm for vector using pointer to class object Pin
BlackDice9-Dec-04 2:42
BlackDice9-Dec-04 2:42 
GeneralRe: 'Find' algorithm for vector using pointer to class object Pin
Jack Puppy9-Dec-04 13:46
Jack Puppy9-Dec-04 13:46 
GeneralCListCtrl and Ado RecordSet Pin
shiraztk8-Dec-04 2:40
shiraztk8-Dec-04 2:40 
GeneralRe: CListCtrl and Ado RecordSet Pin
David Crow8-Dec-04 2:45
David Crow8-Dec-04 2:45 
GeneralRe: CListCtrl and Ado RecordSet Pin
shiraztk8-Dec-04 3:02
shiraztk8-Dec-04 3:02 
GeneralRe: CListCtrl and Ado RecordSet Pin
David Crow8-Dec-04 3:29
David Crow8-Dec-04 3:29 
GeneralNTGraph2D and VC++ .NET Pin
doneirik8-Dec-04 2:32
doneirik8-Dec-04 2:32 
QuestionHow to retrieve a VCProject object? Pin
Franz Klein8-Dec-04 2:17
Franz Klein8-Dec-04 2:17 
QuestionHow to convert BD_ADDR to BT_ADDR? Pin
eli150219798-Dec-04 1:20
eli150219798-Dec-04 1:20 
Questionusing ipconfig....help required??? Pin
shkhan8-Dec-04 0:43
shkhan8-Dec-04 0:43 
QuestionHow to copy files to another computer using Window XP by programming? Pin
dungle308-Dec-04 0:40
dungle308-Dec-04 0:40 
AnswerRe: How to copy files to another computer using Window XP by programming? Pin
David Crow8-Dec-04 2:38
David Crow8-Dec-04 2:38 
GeneralRe: How to copy files to another computer using Window XP by programming? Pin
dungle308-Dec-04 15:08
dungle308-Dec-04 15:08 
GeneralRe: How to copy files to another computer using Window XP by programming? Pin
David Crow9-Dec-04 2:31
David Crow9-Dec-04 2:31 
QuestionHow to minimize the window? Pin
ting6688-Dec-04 0:30
ting6688-Dec-04 0:30 
AnswerRe: How to minimize the window? Pin
ThatsAlok8-Dec-04 1:29
ThatsAlok8-Dec-04 1:29 
AnswerRe: How to minimize the window? Pin
David Crow8-Dec-04 2:40
David Crow8-Dec-04 2:40 

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.