对于A和B哪种类型,简单赋值语句A = B在C ++中合法但在Java中不合法? [英] For what types of A and B is the simple assignment statement A = B legal in C++ but not Java?

查看:63
本文介绍了对于A和B哪种类型,简单赋值语句A = B在C ++中合法但在Java中不合法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的作业中回答了这个问题,尝试了谷歌搜索,但那里也没有运气.

Got this question in my homework, tried googling but no luck there either.

对于什么类型的A和B,简单赋值语句A = B在C ++中是合法的,但是不是Java?

For what types of A and B is the simple assignment statement A = B legal in C++ but not Java?

推荐答案

任何分配了 boolean 的东西都可以.在C ++中,true为任何非零值.在Java中, boolean 是一种类型(并检查了该类型).例如,

Anything with a boolean assignment should do. In C++, true is any non-zero value. In Java, boolean is a type (and that type is checked). For example,

bool a = 1;

是合法的C ++.但是

is legal C++. But

boolean a = 1;

不是合法的Java.此外,如

is not legal Java. Also, as noted by @akuzmiykh the reverse is also true, that is

int a = true;

是合法的C ++,但不是合法的Java.

is legal C++, but not legal Java.

这篇关于对于A和B哪种类型,简单赋值语句A = B在C ++中合法但在Java中不合法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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