B
Bryan Parkoff
I am able to create pointer to function variable as 's2'. m_func1()
function's memory address is copied into s2 variable. Then s2 acts like
pointer to function and is executed without any problem. I do not want
function's memory address to be copied into s2 at run-time. How can I
define at static time? Here is a code below. Notice comment after static
const pmfn1 s2.
class Testpm
{
public:
void m_func1();
int m_num;
typedef void (Testpm::*pmfn1)();
void func();
// static const pmfn1 s2 = &Testpm::m_func1; // error
pmfn1 s2; // OK
static const int n = 2;
};
void Testpm::m_func1()
{
int a = 5;
}
void Testpm::func()
{
s2 = &Testpm::m_func1;
(this->*s2)();
}
int main()
{
Testpm pTestpm;
pTestpm.m_num = 10;
pTestpm.func();
}
function's memory address is copied into s2 variable. Then s2 acts like
pointer to function and is executed without any problem. I do not want
function's memory address to be copied into s2 at run-time. How can I
define at static time? Here is a code below. Notice comment after static
const pmfn1 s2.
class Testpm
{
public:
void m_func1();
int m_num;
typedef void (Testpm::*pmfn1)();
void func();
// static const pmfn1 s2 = &Testpm::m_func1; // error
pmfn1 s2; // OK
static const int n = 2;
};
void Testpm::m_func1()
{
int a = 5;
}
void Testpm::func()
{
s2 = &Testpm::m_func1;
(this->*s2)();
}
int main()
{
Testpm pTestpm;
pTestpm.m_num = 10;
pTestpm.func();
}