c++和运算符的先验知识

c++ and operator precedences

本文关键字:知识 运算符 c++      更新时间:2023-10-16

我知道这个长字符串可以更容易阅读,但我不想这样!

我想得到一个像素的颜色,我正在使用SDL。尽管这与这个问题不是很相关。。。

http://www.gamedev.net/topic/502040-sdl-get-pixel-color/

http://www.libsdl.org/docs/html/sdlsurface.html

显示要获得此颜色值,您需要:

 Uint32 *pixels = (Uint32 *)surface->pixels;
  return pixels[ number ];

好吧,我没有这样的东西,我也想尝试和掌握整个运算符优先级的东西。。

我试了一点,但我无法让它与最后一个操作员一起工作。

所以。。。我得到了这个:

vector<Class*>* pointer_To_A_Vector_With_Pointers;
Class.h: 
vector<Class2*>* get_Another_Vector(); 
Class2.h
SDL_Surface* sdlSurface; 
SDL_Surface.h
has the pixels-array 


Uint32 value =  *(Uint32*) (* pointer_To_A_Vector_With__Pointers[i]->get_Another_Vector()  )[i2]->sdlSurface->pixels;

它应该相当于这样说:

   Uint32 *pixels = (Uint32 *)surface->pixels;

它可以工作,但只检索像素阵列的第一种颜色。但我想实现这一点(行末尾的[数字]):

Uint32 value =  *(Uint32*) (* pointer_To_A_Vector_With__Pointers[i]->get_Another_Vector()  )[i2]->sdlSurface->pixels[ number ];

换句话说,我希望包含最后一个运算符[]sdlSurface->pixels[numbers]

[]的优先级高于*,因此:

 *pointer_To_A_Vector_With__Pointers[i]->get_Another_Vector() 

应该是:

 (*pointer_To_A_Vector_With__Pointers)[i]->get_Another_Vector() 

正如变量名称所示。