c++ passing a const object reference to a function(c++ 将 const 对象引用传递给函数)
问题描述
错误:将 'const QByteArray' 作为 'QByteArray& 的 'this' 参数传递QByteArray::append(const QByteArray&)' 丢弃限定符 [-fpermissive]
error: passing 'const QByteArray' as 'this' argument of 'QByteArray& QByteArray::append(const QByteArray&)' discards qualifiers [-fpermissive]
因为在作为函数参数传递时使对象为 const 是一种惯例,所以我已经做到了.但现在我得到一个错误!,我不想让函数保持不变,因为我必须将 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 对象引用传递给函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:c++ 将 const 对象引用传递给函数


基础教程推荐
- C++详细实现完整图书管理功能 2023-04-04
- 如何C++使用模板特化功能 2023-03-05
- C/C++编程中const的使用详解 2023-03-26
- 详解c# Emit技术 2023-03-25
- C++中的atoi 函数简介 2023-01-05
- C利用语言实现数据结构之队列 2022-11-22
- 一文带你了解C++中的字符替换方法 2023-07-20
- C语言 structural body结构体详解用法 2022-12-06
- C语言基础全局变量与局部变量教程详解 2022-12-31
- C++使用easyX库实现三星环绕效果流程详解 2023-06-26