以前没见过...... [英] Never seen this before ...

查看:70
本文介绍了以前没见过......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的成员函数原型中的第二个const是什么?
dprotect?我相信第一个const会阻止引用返回

被修改,第三个const会阻止成员函数

修改调用它的对象。编译器接受下面的

语句,那么第二个const保护什么呢?

const string const& getPartNumber()const;


干杯,

Bob

解决方案

blangela写道:


下面的成员函数原型中的第二个const是什么?
dprotect?我相信第一个const会阻止引用返回

被修改,第三个const会阻止成员函数

修改调用它的对象。编译器接受下面的

语句,那么第二个const保护什么呢?

const string const& getPartNumber()const;



这是语法错误。


-

Ian Collins。


4月14日,6:31 * pm,Ian Collins< ian-n ... @ hotmail.comwrote:


blangela写道:


下面的成员函数原型中的第二个const是什么?
dprotect?我相信第一个const会阻止引用返回

被修改,第三个const会阻止成员函数

修改调用它的对象。 *编译器接受下面的

语句,那么第二个const保护什么?


const string const& getPartNumber()const;



这是一个语法错误。


-

Ian Collins。



然后为什么编译没有错误(可能会有警告 - 我需要检查
)。


Bob


blangela写道:


4月14日下午6:31, Ian Collins< ian-n ... @ hotmail.comwrote:


> blangela写道:


>>成员函数原型中的第二个const是什么?
dprotect?我相信第一个const会阻止返回的引用被修改,第三个const会阻止成员函数修改调用它的对象。编译器接受下面的
语句,那么第二个const保护什么?
const string const& getPartNumber()const;


这是一个语法错误。



*请*不要引用签名。


>

然后为什么编译时没有错误(可能会有警告 - 我

会有检查)。



#include< string>


struct X

{

const std :: string const& getPartNumber()const;

};


CC z.cc

" z.cc",第5行:错误:const已经包含在这个

的声明中。


g ++ /tmp/z.cc

/tmp/z.cc: 5:错误:重复`const''


-

Ian Collins。


What does the second const in the member function prototype below
dprotect? I believe the first const prevents the reference returned
from being modified and the third prevents the member function from
modifying the object that invokes it. The compiler accepts the
statement below, so what does the second const protect?

const string const &getPartNumber()const;

Cheers,

Bob

解决方案

blangela wrote:

What does the second const in the member function prototype below
dprotect? I believe the first const prevents the reference returned
from being modified and the third prevents the member function from
modifying the object that invokes it. The compiler accepts the
statement below, so what does the second const protect?

const string const &getPartNumber()const;

It''s a syntax error.

--
Ian Collins.


On Apr 14, 6:31*pm, Ian Collins <ian-n...@hotmail.comwrote:

blangela wrote:

What does the second const in the member function prototype below
dprotect? I believe the first const prevents the reference returned
from being modified and the third prevents the member function from
modifying the object that invokes it. *The compiler accepts the
statement below, so what does the second const protect?

const string const &getPartNumber()const;


It''s a syntax error.

--
Ian Collins.

Then why does it compile without errors (there may be warnings - I
will have to check).

Bob


blangela wrote:

On Apr 14, 6:31 pm, Ian Collins <ian-n...@hotmail.comwrote:

>blangela wrote:

>>What does the second const in the member function prototype below
dprotect? I believe the first const prevents the reference returned
from being modified and the third prevents the member function from
modifying the object that invokes it. The compiler accepts the
statement below, so what does the second const protect?
const string const &getPartNumber()const;

It''s a syntax error.

*Please* don''t quote signatures.

>
Then why does it compile without errors (there may be warnings - I
will have to check).

#include <string>

struct X
{
const std::string const &getPartNumber()const;
};

CC z.cc
"z.cc", line 5: Error: "const" has already been included in this
declaration.

g++ /tmp/z.cc
/tmp/z.cc:5: error: duplicate `const''

--
Ian Collins.


这篇关于以前没见过......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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