Function references?

P

Pelle Beckman

Are there such a thing as function References ?

I've done some function Pointer stuff

class MyVariousStuff {
public:
typedef void (*MyFuncPtr)(void*);
SetFuncPtr (MyFuncPtr handle) { m_MyFunc = handle; }
CallFuncPtr () { if (!m_myFunc) return -1; m_myFunc () };

private:
MyFuncPtr m_myFunc;
};

Are there such as thing as function references?
If there are, would thay be preferred in
a situation like this? And how does one use them?

Thanks.

-- Pelle
 
V

Victor Bazarov

Pelle said:
Are there such a thing as function References ?
Yes.

I've done some function Pointer stuff

class MyVariousStuff {
public:
typedef void (*MyFuncPtr)(void*);
SetFuncPtr (MyFuncPtr handle) { m_MyFunc = handle; }
CallFuncPtr () { if (!m_myFunc) return -1; m_myFunc () };

private:
MyFuncPtr m_myFunc;
};

Are there such as thing as function references?
Yes.

If there are, would thay be preferred in
a situation like this?

No. Once you initialise a reference, you cannot re-seat it, and you
clearly want to be able to change what 'm_myFunc' refers to during
run-time.
And how does one use them?

int foo() { return 42; }
int main()
{
int (&fref)() = foo;
return fref();
}


V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top