How to store a function in a member of class? (Using function as callback)
Posted
by
Dane
on Stack Overflow
See other posts from Stack Overflow
or by Dane
Published on 2012-06-17T08:42:52Z
Indexed on
2012/06/17
9:16 UTC
Read the original article
Hit count: 203
c++
|function-pointers
I want to store a function as a class member and call it inside the class? Pretty much like a callback function. My class draw a document but every document must drawn differently. So I want to assign a function (written outside of the class) into one of the members of the class and then call it when I want to draw the document.
This function mostly is responsible for transforming objects according to each specific document.
Here is my class:
class CDocument
{
public:
CDocument();
~CDocument();
void *TransFunc();
}
void Transform()
{
}
int main()
CDocument* Doc = new CDocument();
Doc->TransFunc = Transform();
}
I know that this is probably simple question, but I couldn't find the answer by googling or searching SO.
© Stack Overflow or respective owner