c ++传递一个const对象引用到一个函数 [英] c++ passing a const object reference to a function

查看:158
本文介绍了c ++传递一个const对象引用到一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


错误:传递'const QByteArray'作为'this'参数的'QByteArray& QByteArray :: append(const QByteArray&)'舍弃限定符[-fpermissive]

error: passing 'const QByteArray' as 'this' argument of 'QByteArray& QByteArray::append(const QByteArray&)' discards qualifiers [-fpermissive]

作为函数参数我做到了。
,但现在我得到一个错误!!,
i dnt想让函数常量,因为我必须转换qbyte数组中的数据为短,然后附加另一个数组。

since it is a convention to make objects const while passing as function arguments i have done it. but now i am getting an error!!, i dnt want to make the function constant as i have to convert data in qbyte array into short and then append it another array.

QByteArray ba((const char*)m_output.data(), sizeof(ushort));
    playbackBuffer.append(ba);

我真的需要将这个数组传递给 playbackbuffer ;

这是给我在 playbackBuffer.append(ba);

I really need to pass this array into playbackbuffer;
It is giving me an error on playbackBuffer.append(ba);

请帮助

提前感谢

please help
thanks in advance

推荐答案

这意味着你正在调用一个非const成员函数一个const成员。假设您的 append 函数修改了字节数组。有了const引用,你不应该修改。

This means you are calling a non-const member function on a const member. Presumably, your append function modifies the byte array. With a const reference, you shouldn't be modifying.

这篇关于c ++传递一个const对象引用到一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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