Click here to Skip to main content

C / C++ / MFC

 
GeneralRe: CString assignment crashes on Windows 7 Pinmemberpandit843-Dec-12 6:41 
GeneralRe: CString assignment crashes on Windows 7 PinmvpRichard MacCutchan3-Dec-12 7:22 
AnswerRe: CString assignment crashes on Windows 7 PinmemberStephen Hewitt4-Dec-12 7:34 
GeneralRe: CString assignment crashes on Windows 7 Pinmemberpandit844-Dec-12 20:44 
GeneralRe: CString assignment crashes on Windows 7 [modified] PinmemberStephen Hewitt5-Dec-12 4:49 
AnswerRe: CString assignment crashes on Windows 7 Pinmemberpandit8418-Dec-12 8:48 
GeneralRe: CString assignment crashes on Windows 7 PinmemberStephen Hewitt18-Dec-12 18:44 
QuestionSegmentation Fault in GTK library files PinmemberSrivathsanRaghavan2-Dec-12 20:20 
AnswerRe: Segmentation Fault in GTK library files PinmvpRichard MacCutchan2-Dec-12 22:47 
GeneralRe: Segmentation Fault in GTK library files PinmemberSrivathsanRaghavan2-Dec-12 23:11 
GeneralRe: Segmentation Fault in GTK library files PinmvpRichard MacCutchan2-Dec-12 23:28 
GeneralRe: Segmentation Fault in GTK library files PinmemberSrivathsanRaghavan3-Dec-12 1:25 
GeneralRe: Segmentation Fault in GTK library files PinmvpRichard MacCutchan3-Dec-12 1:55 
Questioncan i use mem_fun like this? PinmemberFalconapollo1-Dec-12 18:37 
I want to set the function pointer at runtime. But i'm stuck here. When i use global function or static class member function, everything is ok. but, when the function is ordinary class member functions. i always got compiler errors. Here is the code:

class A   
{
    int val;
public:
    A() { val = 0; }
    A(int j) { val = j; }
 
    int aFun(int k) {val -= k; return val; }
};
 
typedef int (* func)(int );
class B
{
    func m_addr;
public:
    B(func param)
        : m_addr(param)
    {
 
    }
    void execute()
    {
        cout << m_addr(9) << endl;
    }
};

I'm trying to use them like this:

/* error C2355: 'this' : can only be referenced inside non-static member functions error C2064: term does not evaluate to a function taking 1 arguments class does not define an 'operator()' or a user defined conversion operator to a pointer-to-function or reference-to-function that takes appropriate number of arguments */
A a;
B b(A::aFun); 
b.execute();

after googled a lot, i found that std::mem_fun may be helpful. but i don't know how to use it. anyone can help me?

PS: i'm using Visual C++ 2010
AnswerRe: can i use mem_fun like this? PinmvpRichard MacCutchan1-Dec-12 21:56 
AnswerRe: can i use mem_fun like this? PinmemberStephen Hewitt2-Dec-12 5:45 
AnswerRe: can i use mem_fun like this? Pingroupgoumuli2-Dec-12 7:21 
AnswerRe: can i use mem_fun like this? PinmemberStefan_Lang3-Dec-12 3:14 
AnswerRe: can i use mem_fun like this? PinmemberStefan_Lang3-Dec-12 4:45 
GeneralRe: can i use mem_fun like this? PinmemberFalconapollo4-Dec-12 15:43 
Questionclient server for running the program Pinmemberdanielsutopo1-Dec-12 16:09 
AnswerRe: client server for running the program PinmemberAlbert Holguin1-Dec-12 18:22 
QuestionLimiting selected checkbox items in a CListCtrl Pinmembersoftwaremonkey1-Dec-12 2:40 
SuggestionRe: Limiting selected checkbox items in a CListCtrl PinmemberDavidCrow1-Dec-12 4:51 
AnswerRe: Limiting selected checkbox items in a CListCtrl PinmemberJochen Arndt2-Dec-12 0:56 
GeneralRe: Limiting selected checkbox items in a CListCtrl Pinmembersoftwaremonkey2-Dec-12 23:45 
QuestionUsing VISUAL C++ 6.0 with OLE PinmemberForNow30-Nov-12 10:06 
AnswerRe: Using VISUAL C++ 6.0 with OLE Pinmemberjschell30-Nov-12 11:46 
SuggestionRe: Using VISUAL C++ 6.0 with OLE PinmemberDavidCrow30-Nov-12 15:24 
GeneralRe: Using VISUAL C++ 6.0 with OLE PinmemberForNow4-Dec-12 14:48 
AnswerRe: Using VISUAL C++ 6.0 with OLE PinmemberStephen Hewitt2-Dec-12 5:54 
AnswerRe: Using VISUAL C++ 6.0 with OLE PinmemberCristian Amarie3-Dec-12 9:52 
QuestionDll injection and hooking Pinmemberminiman0630-Nov-12 8:47 
AnswerRe: Dll injection and hooking Pinmemberminiman061-Dec-12 20:01 
Questionsimple program in linux doesnt work Pinmembera1_shay29-Nov-12 23:59 
AnswerRe: simple program in linux doesnt work PinmemberGraham Breach30-Nov-12 1:24 
GeneralRe: simple program in linux doesnt work Pinmembera1_shay30-Nov-12 2:43 
AnswerRe: simple program in linux doesnt work Pinmemberjschell30-Nov-12 11:49 
QuestionRead binary File Pinmemberyogeshs29-Nov-12 0:05 
AnswerRe: Read binary File PinmvpRichard MacCutchan29-Nov-12 0:14 
AnswerRe: Read binary File PinmemberFreak3029-Nov-12 0:18 
GeneralRe: Read binary File Pinmemberyogeshs29-Nov-12 0:41 
QuestionRe: Read binary File PinmemberDavidCrow29-Nov-12 3:37 
Questionextracting resources from an exe for translation Pinmemberchronodekar28-Nov-12 22:28 
AnswerRe: extracting resources from an exe for translation PinmemberMattias G3-Dec-12 23:24 
Questioncompile code twice,why the two result is differrent Pinmemberyingkou28-Nov-12 22:10 
AnswerRe: compile code twice,why the two result is differrent PinmemberStefan_Lang28-Nov-12 23:31 
AnswerRe: compile code twice,why the two result is differrent PinmemberStephen Hewitt29-Nov-12 1:42 
AnswerRe: compile code twice,why the two result is differrent Pinmembersajeesh.c30-Nov-12 19:28 
AnswerRe: compile code twice,why the two result is differrent PinmemberCristian Amarie3-Dec-12 9:55 

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

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


Advertise | Privacy | Mobile
Web02 | 2.8.150414.1 | Last Updated 17 Apr 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid