Jump to content

function pointer .. help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
sp3tsnaz

sp3tsnaz

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
please see the attached code .. dummy.cpp
there is some weird problem regarding function pointer..
its a bit urgent ..

Thankyou in advance.

Attached Files



#2
brownhead

brownhead

    Programmer

  • Members
  • PipPipPipPip
  • 173 posts
Gotta be more descriptive. Where is the problem?

#3
Hassan Seth

Hassan Seth

    Newbie

  • Members
  • PipPip
  • 10 posts
Here goes the description!!

class WordPad;
class Cursor;

class FuncNode{
public:
union Param{
WordPad MyPad;
Cursor MyWord;
}MyParam;
void (State::*func)(int&);
};

class State{
private:
 MyCursor;
WordPad MyDocument;
public:
State(){}
void Func1(int &A);
~State(){}
};

class Functionality{
private:
Shortcut MYShort;
public:
void Func1()
{
Cursor MyC;
FuncNode MyNode;
MyNode.MyParam.MyWord = MyC;
int p = 0;
MyNode.func = &State::Func1;
[SIZE="6"]MyNode.*func (4);[/SIZE]//error
}
};


Error ::
Dummy.cpp func is undeclared

Edited by WingedPanther, 26 December 2009 - 02:49 PM.
fix code tags


#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You don't need to dereference the function pointer to use it. See tutorials here and here for examples.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#5
Hassan Seth

Hassan Seth

    Newbie

  • Members
  • PipPip
  • 10 posts
If Yu want to dereference a functional pointer!

Go Like this:

lets say we have..

class State
{
void Myfunc (int a);
}
void (State::*func) (int);

THis is how yu can assign:

func = &State::Myfunc;

and how dereference.. nd call the function through functional pointerr.. :

You need object of function holder..

State obj;
(obj.*(func)) (2);

Thats it! =)))