Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Explain something to me

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Sat Aug 16, 2008 2:36 pm    Post subject: [C++] Explain something to me Reply with quote

What is this?

Code:
int x = 10;
int *px = &x;
int **ppx;  //<- What the hell is that?


It looks like some kind of pointer, but it has 2 '*'s... And one more thing.

Code:
Class S{
    private:
        int x;
    public:
        S(int temp) : x(temp) {} //<-- What is this also?
};

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Sat Aug 16, 2008 2:53 pm    Post subject: Reply with quote

** means pointer to a pointer. As for the other one, it is a constructor. It is initializing x to whatever value was passed into temp. So if I said:

Code:

S classS(10);


x would now equal 10.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Sat Aug 16, 2008 3:09 pm    Post subject: Reply with quote

** is pointer to a pointer which is used mostly for arrays.


** is two dimensional.

since lets say the first * points to 5 int's
the second star would point to 5x5 = 25.

I'd stay away from lvl 2 pointers they could mess with your head.. you gotta then be thinking everything in the first pointer like every int.. has another pointer pointing to it so it doubles on it self.
Back to top
View user's profile Send private message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Sat Aug 16, 2008 5:05 pm    Post subject: Reply with quote

I didn't know you cna make pointers to pointers. Shocked Does that man you can make pointers to pointers to pointers and etc? And one more thing if you are going to use a pointer to a pointer would you set it up like this?

Code:

int **pp = &*p;

_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Aug 16, 2008 8:24 pm    Post subject: Reply with quote

An example of using ** in a way would be like this:

TCHAR *tszStrings[10];

Thats a pointer to 10 strings.

TCHAR tszStrings[10][10];

Thats a pointer to 10 strings, all with 10 characters of space.

Even when you see

int main( int argc, char *argv[] )

argv is a pointer to a array of characters.

_________________
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Sun Aug 17, 2008 1:20 am    Post subject: Reply with quote

About the pointer, and the pointer to a pointer:
http://www.cplusplus.com/doc/tutorial/pointers.html (there is somewhere a little bit about pointers to pointers
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Sun Aug 17, 2008 2:53 am    Post subject: Reply with quote

HornyAZNBoy wrote:
int **pp = &*p;

Nope. In a declaration (int **pp), * tells the compiler it is a pointer. In an expression (&*p), * dereferences a pointer (gets the value it points to). & gets the address of the variable (aka a pointer to the variable).

So when you do &*p, you get this: *p is equal to int x, so &(*p) is equal to &(x) is equal to p.

What you want is a pointer to p, so you would do int **pp = &p.
pp = &p = &&x
x = *p = **pp

You can have infinite pointers or circular pointers or whatever you want.
void *a, *b;
(void **) a = &b; //tell compiler to pretend a is a double pointer
(void **) b = &a;
*a is b, **a is a, ***a is b, ****a is a

_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites