值语义和指针语义? [英] value semantics and pointer semantics?

查看:202
本文介绍了值语义和指针语义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是价值语义,什么是隐含指针语义的意思?

what does it mean by value semantics and what is mean by implicit pointer semantics?

推荐答案

Java使用隐式指针语义对于基本类型的对象类型和值语义。

Java is using implicit pointer semantics for Object types and value semantics for primitives.

价值语义意味着你直接处理值,并传递副本。
这里的点是,当你有一个值,你可以相信它不会改变背后。

Value semantics means that you deal directly with values and that you pass copies around. The point here is that when you have a value, you can trust it won't change behind your back.

使用指针语义,你不有一个值,你有一个'地址'。

With pointer semantics, you don't have a value, you have an 'address'. Someone else could alter what is there, you can't know.

C ++中的指针语义:

Pointer Semantics in C++ :

void foo(Bar * b) ...
... b->bar() ...

您需要一个*来请求指针语义和 - >在指定的方法上调用方法。

You need an * to ask for pointer semantics and -> to call methods on the pointee.

Java中的隐式指针语义:

Implicit Pointer Semantics in Java :

void foo(Bar b) ...
... b.bar() ...

由于您没有使用值语义的选择,不需要也不区分 - >和。,因此隐含。

Since you don't have the choice of using value semantics, the * isn't needed nor the distinction between -> and ., hence the implicit.

这篇关于值语义和指针语义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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