how to declare pointer for this? thanks
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
// Get screen resolution
long Screen_Res_X = GetSystemMetrics ( SM_CXSCREEN ); //Screen size in x-axis
long Screen_Res_Y = GetSystemMetrics ( SM_CYSCREEN ); //Screen size in y-axis
cout << "Screen size x-axis: " << Screen_Res_X << endl; //Prints x-axis size
cout << "Screen size y-axis: " << Screen_Res_Y << endl; //Prints y-axis size
long GT_X = Screen_Res_X/2; //Declare Gaze Tracker X coordinate
long GT_Y = Screen_Res_Y/2; //Declare Gaze Tracker Y coordinate
cout << "Press \"ESC\" to end program\n";
//Declare pointers
long *pGT_X = GT_X;
long *pGT_Y = GT_Y;
long *pScreen_Res_X = Screen_Res_X;
long *pScreen_Res_Y = Screen_Res_Y;
|
You assign an address to a pointer:
1 2 3
|
int foo; // foo is the int... &foo is the address of the int
int* ptr = &foo; // <-- notice the &
|
so like this??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
// Get screen resolution
long Screen_Res_X = GetSystemMetrics ( SM_CXSCREEN ); //Screen size in x-axis
long Screen_Res_Y = GetSystemMetrics ( SM_CYSCREEN ); //Screen size in y-axis
cout << "Screen size x-axis: " << Screen_Res_X << endl; //Prints x-axis size
cout << "Screen size y-axis: " << Screen_Res_Y << endl; //Prints y-axis size
long GT_X = Screen_Res_X/2; //Declare Gaze Tracker X coordinate
long GT_Y = Screen_Res_Y/2; //Declare Gaze Tracker Y coordinate
//Declare pointers
long *pGT_X;
long *pGT_Y;
long *pScreen_Res_X;
long *pScreen_Res_Y;
//Assign pointers
pGT_X = &aGT_X;
pGT_Y = &aGT_Y;
pScreen_Res_X = &aScreen_Res_X;
pScreen_Res_Y = &aScreen_Res_Y;
|
&aGT_X should be >_X
same as the other 3
That is correct, but you can also assign your variables in their declarations rather than separately:
1 2 3 4 5
|
//Declare and assign pointers
long *pGT_X = >_X;
long *pGT_Y = >_Y;
long *pScreen_Res_X = &Screen_Res_X;
long *pScreen_Res_Y = &Screen_Res_Y;
|
And there is also an edit button on your posts. Please make use of it.
thanks
oh short question i cant do this can i if (x < y < z)
?
you can, but it doesn't do what you think it does/want it to.
Topic archived. No new replies allowed.