简体   繁体   中英

C++ pointer to a class method call

In my class Tabla I have a public pointer to method:

public:
    int (Tabla :: *punterofunc)(int,int);

In main I point it to a class method:

tablita.punterofunc = &Tabla :: in_lineal;

But this call doesn't work!

 tablita->punterofunc(num,0);

I think you're looking for this tasty syntax:

((tablita).*(tablita.punterofunc))(num,0);

tablita.punterofunc is a member function pointer. The general syntax for calling a pointer-to-member-function p on an object o is:

((o).*(p))(args...);

Just apply that to your code. (Some of the parens might not be necessary in all cases (not sure), but if you stick with that, it should work all the time.)

尝试这个:

tablita.*punterofunc(num,0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM