Co to jest operator -> * w C ++?
C ++ nadal mnie zaskakuje. Dzisiaj dowiedziałem się o operatorze -> *. Jest przeciążalny, ale nie mam pojęcia, jak go wywołać. Udaje mi się go przeciążać w mojej klasie, ale nie mam pojęcia, jak to nazwać.
struct B { int a; };
struct A
{
typedef int (A::*a_func)(void);
B *p;
int a,b,c;
A() { a=0; }
A(int bb) { b=b; c=b; }
int operator + (int a) { return 2; }
int operator ->* (a_func a) { return 99; }
int operator ->* (int a) { return 94; }
int operator * (int a) { return 2; }
B* operator -> () { return p; }
int ff() { return 4; }
};
void main()
{
A a;
A*p = &a;
a + 2;
}
edytować:
Dzięki odpowiedzi. Aby wywołać przeciążoną funkcję, piszę
void main()
{
A a;
A*p = &a;
a + 2;
a->a;
A::a_func f = &A::ff;
(&a->*f)();
(a->*f); //this
}