c++和运算符的先验知识
c++ and operator precedences
我知道这个长字符串可以更容易阅读,但我不想这样!
我想得到一个像素的颜色,我正在使用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()
正如变量名称所示。
相关文章:
- 为什么比较运算符如此快速
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 使用C++中的模板和运算符重载执行矩阵运算
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 增量运算符与后缀混淆
- 一个关于在C++中重载布尔运算符的问题
- 运算符C++ "delete []"仅删除 2 个前值
- 模板类无法识别友元运算符
- 我可以使用条件运算符初始化C风格的字符串文字吗
- 关闭||运算符优化
- 通过继承类使用来自不同命名空间的运算符
- C++Cast运算符过载
- 如何使用AngelScript注册SFML Vector2运算符
- 重载元组索引运算符-C++
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 布尔比较运算符是如何在C++中工作的
- 重载运算符new[]的行为取决于析构函数
- c++和运算符的先验知识