0

I am trying to store a pointer to a member function in a structure which will be used to call the function later in my program.

Something like this:

// abc.h
namespace XYZ {
typedef void func(const uint8_t *buf, int len);
struct holder
{
    // other members
    func * storePtr;
}
} // end of namespace

the other file as:

// pqr.h
#include abc.h
namespace XYZ {
 class pqr {
   // data members and other functions
   void func1(const uint8_t *buffer, int length);
   void func2(func *section);
   void func3();
   }
} // end of namespace

Now my cpp file needs to store instance of this func1 in my structure member storePtr

// app.cpp
#include pqr.h
void pqr::funct3()
{
   // Do something
   func2(func1);
}
void pqr::func2(func * section)
{
   holder h;
   h.storePtr = section;
}

But I am getting compilation error at line "func2(func1);" as "error C3867: 'pqr::func1': function call missing argument list; use '&pqr::func1' to create a pointer to member"

I have used &pqr:: to define the scope but it also doesn't solve my problem and I am not able to understand what to do.

4

1 回答 1

1

Pointers to member function are not the same thing as pointers to normal functions - have a look at the explanation and example here: http://msdn.microsoft.com/en-us/library/k8336763.aspx

于 2012-03-20T19:38:28.047 回答