Опитвам се да получа адреса на членска функция, но не знам как. Ще съм благодарен, ако някой може да ми каже какво правя грешно. Както можете да видите в моя пример по-долу, нито (long)&g, нито (long)&this->g работят и не мога да разбера правилния синтаксис:
/* Create a class that (redundantly) performs data member selection
and a member function call using the this keyword (which refers to the
address of the current object). */
#include<iostream>
using namespace std;
#define PR(STR) cout << #STR ": " << STR << endl;
class test
{
public:
int a, b;
int c[10];
void g();
};
void f()
{
cout << "calling f()" << endl;
}
void test::g()
{
this->a = 5;
PR( (long)&a );
PR( (long)&b );
PR( (long)&this->b ); // this-> is redundant
PR( (long)&this->c ); // = c[0]
PR( (long)&this->c[1] );
PR( (long)&f );
// PR( (long)&g ); // this doesn't work
// PR( (long)&this->g ); // neither does this
cout << endl;
}
int main()
{
test t;
t.g();
}
Благодаря предварително!
Благодаря ви за отговора! Все още обаче не го карам да работи. Ако сменя линията
PR( (long)&g );
to
PR( (long)&test::g );
, пак не става.
PR( &test::g );
работи в main(), но не
PR( (long)&test::g );
???
Мисля, че пропускам нещо. :(