Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <typeinfo>
- template <class T>
- void Output(const char * Str, T Func)
- {
- void *Ptr = reinterpret_cast<void *>(Func);
- std::ptrdiff_t Num = reinterpret_cast<std::ptrdiff_t>(Ptr);
- std::cout << Str << " " << Num << std::endl;
- }
- class TAnotherBase { long a[10]; };
- struct TBase {
- typedef void (TBase::*TFunc)();
- TFunc Func;
- TBase(TFunc F) {
- Func = F;
- Output("Ctor TBase ", Func);
- }
- void CallF() {
- std::cout << "This in TBase: " << typeid(this).name() << " " << this << std::endl;
- (this->*Func)();
- }
- };
- struct TDerived: public TAnotherBase, public TBase {
- TDerived(): TBase(static_cast<TBase::TFunc>(&TDerived::F)) {
- Output("Ctor TDerived ", &TDerived::F);
- CallF();
- }
- void F() {
- std::cout << "This in TDerived::F: " <<typeid(this).name() << " " << this << std::endl;
- }
- };
- int main(int argc, char **argv) {
- TDerived Derived;
- return 0;
- }
- Ctor TBase 4197502 (1)
- Ctor TDerived 4197502 (2)
- This in base: P5TBase 0x7fff6b30fc00 (3)
- This in TDerived::F: P8TDerived 0x7fff6b30fbb0 (4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement