Calling private method in C++

后端 未结 12 2175
忘了有多久
忘了有多久 2020-11-27 20:02

This is purely a theoretical question, I know that if someone declares a method private, you probably shouldn\'t call it. I managed to call private virtual methods and chang

12条回答
  •  眼角桃花
    2020-11-27 20:56

    If we are speaking of MSVC, I think the simplest way with no other harm than the fact of calling a private method itself is the great __asm:

    class A
    {
    private:
        void TestA () {};
    };
    
    A a;
    __asm
    {
        // MSVC assumes (this) to be in the ecx.
        // We cannot use mov since (a) is located on the stack
        // (i.e. [ebp + ...] or [esp - ...])
        lea     ecx, [a]
        call    A::TestA
    }
    

提交回复
热议问题