gpt4 book ai didi

c++ - vc6到vs2010移植错误

转载 作者:行者123 更新时间:2023-11-28 03:19:12 24 4
gpt4 key购买 nike

我被困在将我的项目从 VC6 移植到 VS2010 的过程中。请任何人帮助我。

void CEdchLoop::ReceiveSdu(UINT8* Sdu, UINT32 BitLength, int Fn)
{
UINT8* pPdu = Sdu;
int Bit = 8;

UINT32 SourceId = GetBitsL(pPdu, BitLength, Bit, 32);
UINT32 PduUniqueId = GetBitsL(pPdu, BitLength, Bit, 32);
}

在上面的代码中,我收到错误 C2664: 'GetBitsL' : cannot convert parameter 1 from 'UINT8 *' to 'const UINT8 *&'

并且 GetBitsL 定义为 UINT32 GetBitsL(const UINT8*& Bin, UINT32& BitLength, int& Bit, int Count)

请任何人帮助我解决这个问题。如果这不是一个很好的问题,我很抱歉。但是傻五分钟总比永远傻好。

提前致谢。

最佳答案

这个问题最好用一个演示来解释:

int * ip;
const int *& cipr = ip;

好的,此时,cipr 是对ip 的引用。这是不合法的,您将在以下部分中了解原因。

const int * cip = some_const_data;
cipr = cip;

该赋值是合法的,因为作为(引用)指向 const 数据的指针,cipr 被允许赋值以指向 const 数据。但正因为如此,因为 cipr 是对 ip 的引用,所以现在 ip 指向 const 数据。这是一个问题:

*ip = 7;

这是合法的,因为ip 的类型是指向非const int 的指针。然而,通过上面的一些技巧,我们让它指向常量数据。这是不允许的,因此我们将 cipr 绑定(bind)到引用 ip 的初始声明一定是非法的。这与您通过将 pPdu 传递给 GetBitsL 来尝试做的事情相同。

关于c++ - vc6到vs2010移植错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15963126/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com