Click here to Skip to main content
15,912,578 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Generalhelp! VC++ project desktop access in LAN Pin
B4u13-Oct-02 17:22
B4u13-Oct-02 17:22 
GeneralRe: help! VC++ project desktop access in LAN Pin
jmkhael14-Oct-02 0:41
jmkhael14-Oct-02 0:41 
GeneralVisual C++ and Windows XP Pin
dinger13-Oct-02 16:52
dinger13-Oct-02 16:52 
GeneralRe: Visual C++ and Windows XP Pin
Nish Nishant13-Oct-02 17:10
sitebuilderNish Nishant13-Oct-02 17:10 
GeneralRe: Visual C++ and Windows XP Pin
Jon Hulatt13-Oct-02 21:35
Jon Hulatt13-Oct-02 21:35 
GeneralRe: Visual C++ and Windows XP Pin
Gero Gerber14-Oct-02 7:11
Gero Gerber14-Oct-02 7:11 
GeneralRe: Visual C++ and Windows XP Pin
dinger15-Oct-02 6:28
dinger15-Oct-02 6:28 
GeneralHelp with STL and Function Adapters Pin
Neville Franks13-Oct-02 16:21
Neville Franks13-Oct-02 16:21 
Bit my bit I'm trying to make more use of STL, but it is a painfull process at times.

The following code is text book stuff, but I can't get it to compile. In particular I would like to call class member function which has a parameter from for_each(), find_if() etc.

Here is the code:

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

using std::vector;
using std::for_each;
using std::bind2nd;
using std::mem_fun_ref;
using std::string;


void Test_find();

int main(int argc, char* argv[])
{
    Test_find();

    return 0;
}


class Person
{
public:
            Person() {};
            Person( char* pszName ) { m_Name = pszName; }

    int  print()
        { std::cout << m_Name << std::endl; return 0; }
            
    int printWithPrefix( std::string prefix )
        { std::cout << prefix << m_Name << std::endl; return 0; }

    std::string m_Name;
};


void GPrint( Person person )
{
    std::cout << person.m_Name << std::endl;
}


void
Test_find()
{
    std::vector<Person> col1;
    col1.push_back( Person( "Neville" ) );
    col1.push_back( Person( "Cherryl" ) );

    for_each( col1.begin(), col1.end(), &GPrint );    // compiles & works

    for_each( col1.begin(), col1.end(), mem_fun_ref( &Person::print ) );

    for_each( col1.begin(), col1.end(), bind2nd( mem_fun_ref( &Person::printWithPrefix ), "person: " ) );
    // Line above gives this VC6 error:
    // d:\libs\tests\teststl.cpp(68) : error C2784: 'class std::mem_fun_ref_t<_R,_Ty> __cdecl std::mem_fun_ref(_R (__thiscall _Ty::*)(void))' : could not deduce template argument for '<Unknown>' from 'int (__thiscall Person::*)(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)'
}


Blank lines somehow are missing above!

Neville Franks, Author of ED for Windows. www.getsoft.com
GeneralRe: Help with STL and Function Adapters Pin
Anonymous13-Oct-02 19:24
Anonymous13-Oct-02 19:24 
GeneralRe: Help with STL and Function Adapters Pin
Neville Franks13-Oct-02 19:58
Neville Franks13-Oct-02 19:58 
GeneralRe: Help with STL and Function Adapters Pin
Joaquín M López Muñoz13-Oct-02 21:13
Joaquín M López Muñoz13-Oct-02 21:13 
GeneralRe: Help with STL and Function Adapters Pin
Neville Franks13-Oct-02 21:33
Neville Franks13-Oct-02 21:33 
GeneralRe: Help with STL and Function Adapters Pin
Joaquín M López Muñoz13-Oct-02 21:35
Joaquín M López Muñoz13-Oct-02 21:35 
GeneralRe: Help with STL and Function Adapters Pin
Stuart Dootson14-Oct-02 18:55
professionalStuart Dootson14-Oct-02 18:55 
GeneralRe: Help with STL and Function Adapters Pin
Neville Franks14-Oct-02 19:18
Neville Franks14-Oct-02 19:18 
GeneralRe: Help with STL and Function Adapters Pin
Stuart Dootson15-Oct-02 7:33
professionalStuart Dootson15-Oct-02 7:33 
QuestionHow To Declare This Array? Pin
ooosawaddee313-Oct-02 9:52
ooosawaddee313-Oct-02 9:52 
AnswerRe: How To Declare This Array? Pin
Navin13-Oct-02 9:55
Navin13-Oct-02 9:55 
AnswerRe: How To Declare This Array? Pin
BlackKettle13-Oct-02 10:08
BlackKettle13-Oct-02 10:08 
GeneralRe: How To Declare This Array? Pin
Jon Hulatt13-Oct-02 21:37
Jon Hulatt13-Oct-02 21:37 
GeneralRe: How To Declare This Array? Pin
Michael Dunn14-Oct-02 1:04
sitebuilderMichael Dunn14-Oct-02 1:04 
GeneralFLOAT/STRING conversions Pin
Atlence13-Oct-02 9:10
Atlence13-Oct-02 9:10 
GeneralRe: FLOAT/STRING conversions Pin
Joaquín M López Muñoz13-Oct-02 9:21
Joaquín M López Muñoz13-Oct-02 9:21 
GeneralRe: FLOAT/STRING conversions Pin
Atlence14-Oct-02 1:37
Atlence14-Oct-02 1:37 
GeneralRe: FLOAT/STRING conversions Pin
Jason Henderson13-Oct-02 17:14
Jason Henderson13-Oct-02 17:14 

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.