现行标准合法吗? [英] current standard is it legal?

查看:88
本文介绍了现行标准合法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在未命名的时事中调用nonconst成员函数?


ex:

class String {

public :

void doSomething();


};


String createString();

createString()。doSomething();


好​​吗?


谢谢。

is it possible to call nonconst member function on an unnamed temprary?

ex:
class String{
public:
void doSomething();

};

String createString();
createString().doSomething();

is it ok?

thanks.

推荐答案

puzzlecracker写道:
puzzlecracker wrote:
是否有可能在一个未命名的时事上调用nonconst成员函数?

ex:
class String {
public:
void doSomething();

};

字符串createString();
createString ().doSomething();

好吗?

谢谢。
is it possible to call nonconst member function on an unnamed temprary?

ex:
class String{
public:
void doSomething();

};

String createString();
createString().doSomething();

is it ok?

thanks.



编号一个未命名的临时版是一个r- value(又名const)。


No. An unnamed temporary is an r-value (aka const).


" red floyd" <无***** @ here.dude>在消息中写道

新闻:VE ***************** @ newssvr13.news.prodigy.co m
"red floyd" <no*****@here.dude> wrote in message
news:VE*****************@newssvr13.news.prodigy.co m
puzzlecracker写道:
puzzlecracker wrote:
是否可以在未命名的文件上调用nonconst成员函数? ex:
class String {
public:
void doSomething();

};

String createString();
createString()。doSomething();

好吗?

谢谢。
is it possible to call nonconst member function on an unnamed
temprary? ex:
class String{
public:
void doSomething();

};

String createString();
createString().doSomething();

is it ok?

thanks.


否。一个未命名的临时值是一个r值(又名const)。


No. An unnamed temporary is an r-value (aka const).




我不认为右值必然是常量。我不认为任何类对象

是const,除非以这种方式声明。 Comeau编译代码而没有

异议。但是,如果createString返回const String,它就不会编译。


-

John Carson



I don''t think an rvalue is necessarily const. I don''t think any class object
is const unless declared that way. Comeau compiles the code without
objection. However, it won''t compile if createString returns const String.

--
John Carson


在文章< 11 ********************** @ f14g2000cwb.googlegroups .com>,

puzzlecracker< ir ********* @ gmail.com>写道:
In article <11**********************@f14g2000cwb.googlegroups .com>,
puzzlecracker <ir*********@gmail.com> wrote:
是否可以在一个未命名的临时文件上调用nonconst成员函数?

ex:
class String {
public:
void doSomething();

};

字符串createString();
createString()。doSomething();

是吗好吗?
is it possible to call nonconst member function on an unnamed temprary?

ex:
class String{
public:
void doSomething();

};

String createString();
createString().doSomething();

is it ok?




是。


第3.10节第5段:

调用a的结果不返回引用的函数是

一个右值。用户定义的运算符是函数,这些运算符期望或产生左值的是否由它们的参数和

返回类型决定。


第3.10节第10段:

为了修改对象需要对象的左值

,除了类型的右值也可以用来修改它

在某些情况下指示。 [示例:成员函数

调用对象(9.3)可以修改对象。]


(第9.3节引用成员函数。) />

-

Mark Ping
em * ***@soda.CSUA.Berkeley.EDU


这篇关于现行标准合法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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