Redian新闻
>
请问媒体报道是指什么?报纸,电视,互联网?
avatar
请问媒体报道是指什么?报纸,电视,互联网?# Immigration - 落地生根
a*2
1
class A
{
int x;
public:
A(int x_):x(x_){}
int& getX(){return x;}
};
A a1(10);
A a2(10);
int& y = a1.getX();
y = a2.getX();
y = 20;
a1和a2中的结果分别是什么?
第一个改变了
第二个没改变
什么原因?
avatar
r*h
2
什么级别的可以算数? 多谢!
avatar
l*l
3
int& y = a1.getX(); this one is reference variable initialization, make y
the reference to a1.x.
y = a2.getX(); is just assignment, make a1.x = a2.x
y = 20; another assignment, make a1.x = 20.
avatar
F*n
4
Printed media(news paper,magazine,book...)
TV or radio need transcript.
什么级别的可以算数?
the circulation of the media is national or internation.
avatar
a*2
5
哦,有道理,简单概念没弄清,多谢

【在 l******l 的大作中提到】
: int& y = a1.getX(); this one is reference variable initialization, make y
: the reference to a1.x.
: y = a2.getX(); is just assignment, make a1.x = a2.x
: y = 20; another assignment, make a1.x = 20.

avatar
r*y
6
I think there would have been compiler error here since it is trying
to change a private member through reference.
But I run this and it is ok.
So we can not change a private member directly but we can
change the private member through reference or pointer.

【在 a**********2 的大作中提到】
: class A
: {
: int x;
: public:
: A(int x_):x(x_){}
: int& getX(){return x;}
: };
: A a1(10);
: A a2(10);
: int& y = a1.getX();

avatar
m*l
7
yea, that's why the stupid '&' was invented.
that's the design of C++, encapsulation is to hide code from OTHER code,
not the programmer.
Same logic applies to 'friend'

【在 r*******y 的大作中提到】
: I think there would have been compiler error here since it is trying
: to change a private member through reference.
: But I run this and it is ok.
: So we can not change a private member directly but we can
: change the private member through reference or pointer.

avatar
m*l
8
你试下这个:
class A
{
int x;
public:
A(int x_):x(x_){}
int& getX(){return x;}
};
A a1(11);
A a2(10);
int& y = a1.getX();
cout << y;
y = a2.getX();
cout << y;
y = 20;
cout << y;
看看结果是啥.
y = a2.getX() 是10吗?
is this the case why reference variable can't be reassigned to a new
reference?

【在 a**********2 的大作中提到】
: 哦,有道理,简单概念没弄清,多谢
avatar
r*y
9
I like reference. pointer is too complicated

【在 m********l 的大作中提到】
: yea, that's why the stupid '&' was invented.
: that's the design of C++, encapsulation is to hide code from OTHER code,
: not the programmer.
: Same logic applies to 'friend'

avatar
b*8
10
引用只能地址初始化一次。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。