Click here to Skip to main content
15,905,233 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: AfxMessageBox("Simple message box."); Pin
Neville Franks24-Oct-04 0:12
Neville Franks24-Oct-04 0:12 
GeneralRe: AfxMessageBox("Simple message box."); Pin
Programmer_Chris24-Oct-04 1:00
Programmer_Chris24-Oct-04 1:00 
GeneralRe: AfxMessageBox("Simple message box."); Pin
Neville Franks24-Oct-04 1:55
Neville Franks24-Oct-04 1:55 
GeneralRe Pin
yanping wang24-Oct-04 2:49
yanping wang24-Oct-04 2:49 
GeneralRe: Re Pin
Programmer_Chris24-Oct-04 3:23
Programmer_Chris24-Oct-04 3:23 
GeneralTough time with template syntax Pin
LynnJ23-Oct-04 19:04
LynnJ23-Oct-04 19:04 
GeneralRe: Tough time with template syntax Pin
Bob Stanneveld24-Oct-04 2:19
Bob Stanneveld24-Oct-04 2:19 
GeneralRe: Tough time with template syntax Pin
Andrew Walker24-Oct-04 4:34
Andrew Walker24-Oct-04 4:34 
My suggestion is that you don't even try to write a templated search function like this, the standard library provides the std::find_if template for this situation - not to mention providing a more generalised interface for modifying the search criteria.

For example, a very simple employee search might look something like this:

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

using namespace std;

struct Employee {
    Employee(string n, int i) : name(n), id(i) {  }

    int id;
    string name;
};

struct EmpName
{
    EmpName(string toFind) : searchName(toFind) { }

    bool operator()(Employee& e) {
        if(e.name == searchName) {
            return true;
        }
        return false;
    }

    string searchName;
};

int main()
{
    vector<Employee> employees;
    employees.push_back( Employee("bob", 0) );
    employees.push_back( Employee("john",1) );
    employees.push_back( Employee("mary",2) );
    employees.push_back( Employee("fred",3) );
    vector<Employee>::iterator searchResult;
    searchResult = std::find_if(employees.begin(),employees.end(),EmpName("john"));
    if(searchResult != employees.end())
    {
        cout << (*searchResult).id << endl;
    }
    else
    {
        cout << "not found" << endl;
    }
}



If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts your aim;
Yours is the Earth and everything that's in it.

Rudyard Kipling

GeneralRe: Tough time with template syntax Pin
Kevin McFarlane24-Oct-04 5:12
Kevin McFarlane24-Oct-04 5:12 
GeneralRe: Tough time with template syntax Pin
Kevin McFarlane24-Oct-04 5:10
Kevin McFarlane24-Oct-04 5:10 
QuestionUsing Flash Animations? Pin
dSolariuM23-Oct-04 18:12
dSolariuM23-Oct-04 18:12 
AnswerRe: Using Flash Animations? Pin
jan larsen26-Oct-04 4:02
jan larsen26-Oct-04 4:02 
GeneralASTL in visual C++ Pin
xmasglee23-Oct-04 17:52
xmasglee23-Oct-04 17:52 
Generaladding templates into visual C++ Pin
xmasglee23-Oct-04 17:51
xmasglee23-Oct-04 17:51 
GeneralRe: adding templates into visual C++ Pin
Bob Stanneveld24-Oct-04 2:27
Bob Stanneveld24-Oct-04 2:27 
General.Net Pro .VS. VC++ 6. Pin
thompsons23-Oct-04 14:13
thompsons23-Oct-04 14:13 
GeneralRe: .Net Pro .VS. VC++ 6. Pin
SuperTank23-Oct-04 14:35
SuperTank23-Oct-04 14:35 
GeneralRe: .Net Pro .VS. VC++ 6. Pin
burrifro7923-Oct-04 15:01
burrifro7923-Oct-04 15:01 
QuestionHow do I import a class? Pin
SuperTank23-Oct-04 13:30
SuperTank23-Oct-04 13:30 
AnswerRe: How do I import a class? Pin
ThatsAlok24-Oct-04 22:41
ThatsAlok24-Oct-04 22:41 
GeneralRe: Linking library Pin
BlackDice23-Oct-04 10:26
BlackDice23-Oct-04 10:26 
Generalconsole app closes Pin
jerrodab23-Oct-04 9:52
jerrodab23-Oct-04 9:52 
GeneralRe: console app closes Pin
SuperTank23-Oct-04 10:01
SuperTank23-Oct-04 10:01 
GeneralRe: console app closes Pin
Anonymous23-Oct-04 16:06
Anonymous23-Oct-04 16:06 
GeneralGrabbing images from Video Files Pin
AJ12323-Oct-04 9:18
AJ12323-Oct-04 9:18 

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.