Originally Posted by
cxl2253
typedef void (__stdcall * STORESCUCALLBACK)(T_StoreProgress* progress);
class myclass
{
static STORESCUCALLBACK mystorecallback;
}
STORESCUCALLBACK myclass::mystorecallback=NULL;
typedef void (__stdcall * STORESCUCALLBACK)(T_StoreProgress* progress);
class myclass
{
static STORESCUCALLBACK mystorecallback;
}
STORESCUCALLBACK myclass::mystorecallback=NULL;
To copy to clipboard, switch view to plain text mode
I can't see nothing wrong in this example. The error maybe caused by something else. Below is a sample code with static pointer to function and with passing pointer to function to method:
// Test.h
#ifndef TEST_H_
#define TEST_H_
typedef int (* FUNC_PTR)(int, int);
class Test
{
public:
static int add(int l, int r);
static int mul(int l, int r);
static FUNC_PTR funcPtr; // declaration of static pointer to function
void doTheJob();
private:
int callback(FUNC_PTR f, int l, int r); // declaration of function with parameter
};
#endif
// Test.h
#ifndef TEST_H_
#define TEST_H_
typedef int (* FUNC_PTR)(int, int);
class Test
{
public:
static int add(int l, int r);
static int mul(int l, int r);
static FUNC_PTR funcPtr; // declaration of static pointer to function
void doTheJob();
private:
int callback(FUNC_PTR f, int l, int r); // declaration of function with parameter
};
#endif
To copy to clipboard, switch view to plain text mode
// Test.cpp
#include "Test.h"
#include <iostream>
FUNC_PTR
Test::funcPtr = NULL; // definition of static pointer to function
int
Test::add(int l, int r) {
return l+r;
}
int
Test::mul(int l, int r) {
return l*r;
}
int
Test::callback(FUNC_PTR f, int l, int r) {
return f(l, r);
}
void
Test::doTheJob() {
int result = callback(funcPtr, 2, 5);
std::cout << "result = " << result << std::endl;
}
// Test.cpp
#include "Test.h"
#include <iostream>
FUNC_PTR
Test::funcPtr = NULL; // definition of static pointer to function
int
Test::add(int l, int r) {
return l+r;
}
int
Test::mul(int l, int r) {
return l*r;
}
int
Test::callback(FUNC_PTR f, int l, int r) {
return f(l, r);
}
void
Test::doTheJob() {
int result = callback(funcPtr, 2, 5);
std::cout << "result = " << result << std::endl;
}
To copy to clipboard, switch view to plain text mode
// main.cpp
#include "Test.h"
int main ()
{
Test test;
test.funcPtr = Test::add;
test.doTheJob();
test.funcPtr = Test::mul;
test.doTheJob();
}
// main.cpp
#include "Test.h"
int main ()
{
Test test;
test.funcPtr = Test::add;
test.doTheJob();
test.funcPtr = Test::mul;
test.doTheJob();
}
To copy to clipboard, switch view to plain text mode
Bookmarks