Can't use pointer to member function inside main()?

I

Immortal Nephi

My code may sound strange. I define pF inside class. pF is a pointer
to member function. You can choose one of three member function's
memory address and put it into pF. Only one member function as F() is
able to invoke pF, but you can't invoke pF inside main(). To reduce
CPU's overhead so you don't need to invoke F() and you can invoke pF
directly. Take a look at my code.

Please forgive me if you complain that my post is not wrapped with
single line. I have no control to post using Google newsgroups.

class Test
{
public:
Test() { }
~Test() {}
void F1() { pF = &Test::F2; }
void F2() { pF = &Test::F3; }
void F3() { pF = &Test::F1; }

void (Test::*pF)();

void F() { (this->*pF)(); }
};

int main(void)
{
Test test;

test.pF = &Test::F1;

test.(Test::*pF)(); // Error

test.F();
test.F();
test.F();
test.F();

return 0;
}
 

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

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top