C ++初级问题:解引用对乘法 [英] C++ beginner question: dereference vs multiply

查看:340
本文介绍了C ++初级问题:解引用对乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是进入C ++。当我看到乘法符号( * )被用于表示变量的取消引用时,我会不断地被抛弃。



例如:
unsigned char * pixels = vidgrabber.getPixels();



这会抛弃别人吗?



谢谢。






pps我有另一个相当简单的问题,没有得到回答:(这里:
解决方案

C和继承C ++,被操作符淹没,并且内在上下文敏感。你必须习惯它:



如果 * 在要声明的变量名称 (或定义)之前出现 类型修饰符 ,并使该变量成为指针。

如果是 一元前缀操作符 >对于作为表达式一部分的变量, 取消引用(或任何重载的内容)。

如果是



(从这里可以看到 * / code>不是取消引用的一元前缀,而是一个类型修饰符。)



注意 & 几乎类似于 * ,只是它的含义是不同的:它使一个变量引用 -of运算符,或二进制AND。


Just getting into C++. I'm getting constantly thrown off track when I see the symbol for multiply (*) being used to denote the dereferencing of a variable

for example: unsigned char * pixels = vidgrabber.getPixels();

Does this throw other people off? What's the tip for getting my head around this?

Thank you.


p.s. I have another reasonably simple question, that didn't get answered :( here: beginner question: add/subtract to value rather than just be that value pretty please! and thanks for your time!

解决方案

C, and by inheritance C++, are swamped with operators and are inherently context-sensitive. You will have to get used to it:

If * appears before the name of a variable that is being declared (or defined), it's a type modifier and makes that variable a pointer.
If it is a unary prefix operator for a variable that is part of an expression, it's dereferencing (or whatever it's been overloaded to).
If it is a binary infix operator for two variables that are part of an expression, it's multiplication (or whatever it's been overloaded to).

(From this you can see that the * in your unsigned char * pixel isn't a dereferencing unary prefix, but a type modifier.)

Note that & pretty much resembles *, only it's meaning is different: it makes a variable a reference, is the address-of operator, or the binary AND.

这篇关于C ++初级问题:解引用对乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆