this pointer question!

Hello!

I have googled alot and i find absolutely nothing on this subject.

if i call a function this inside a class with the this pointer does it return from the current function?

Maybe calling member functions with the this pointer is no good idea?

I found it useful for making the code "Sorted" and it looked good for me.

I excuse my bad english!

Thank you in advance!

EDIT: I wrote a program to test this. I dont know why i didnt thought of that before. It did not return. Is it possible to make it return and call a member function using the this pointer at the same time?
Last edited on
What do you mean to say? Your english isn't that bad, but I'm not sure what it is you're trying to ask.

class thisclass
{
void func1()
{
this->func2()
}

void func2()
{
//Do something else!
}

};

That was what i meant
Last edited on
I understood it that far, but what exactly is your problem with that?
This should mean that you call func2() of thisclass in func1().
But why would you want to do that if you already have all the privileges to call any function/data in thisclass by
1
2
3
4
5
6
7
8
9
10
11
class thisclass
{
  void func1()
  {
     func2()  //<--No need to use this pointer
  }
  void func2()
  {
     //Do something else!
  }
};
Last edited on
Oh, this is embarrasing. Im am currently working on a SDL game and i wanted to make a class for my game and call all the class member functions from the gameloop function. and i thougt you could only call member functions using the this keyword. But i dont know where i have got that from. Hehe. Well thank you! :)
this->func2(); and func2(); are equivalent in this case - If you're using this-> it's more explicit though, so I prefer that style.
closed account (zb0S216C)
Sometimes, though, it's required. For instance:

1
2
3
4
5
6
7
8
9
10
11
12
struct Base
{
    Base(int Init = 0) : A(Init) { }
    int A;
};

struct Child : public Base
{
    Child() : Base(), IsZero(this->A == 0) { }

    bool IsZero;
};

Wazzak
Last edited on
Topic archived. No new replies allowed.