c++pointersstackthisactivation

C++ Stack Frame/Activation Record and 'this' pointer


This is my first post here, if I am messing something up I would appreciate any advice. Does C++ implement an activation record? My experience with this has been largely with Java so I am unsure if it is the same for other languages. If so, in C++ is it correct to say that 'this' is a pointer to the previous record on the activation stack? For example:

...
class Example {
private:
    int num;
public:
    void setNum(int num) {
        this->num = num;
    }
...

So the activation stack would have an 'Example' object on the stack and then when the function 'setNum(...)' is called it would put that call on the activation stack. So 'this' would be of type Example* and would point to the 'Example' object that is on the stack before the function call. Is that correct? Thanks all!


Solution

  • this only exists within a class or struct. It does not exists within a free function.

    this points to the object whose member function is called.

    In your case, this points to an instance of Example and thus the type is Example*

    I don't know the term ActivationRecord. C++ doesn't know the concept of a function stack, that's just an implementation detail.