notes/pl/cpp/tricks/cpp-devirtualization.txt
Ihar Hancharenka 5dff80e88e first
2023-03-27 16:52:17 +03:00

20 строки
372 B
Plaintext

class Base
{
typedef void (*FP)();
typedef int (*FPGet) (const Base &);
typedef void (*FPSet) (Base &, int);
static FP vtbl[totalMethods][totalClasses];
uint8_t tag;
public:
int get() const {
return ((FPGet)(vtbl[0][tag]))(*this);
}
void set(int x) {
((FPSet)vtbl[1][tag])(*this, x);
}
};
// double index is just a single address calculation.