操作员无法匹配
no match for operator
本文关键字:操作员 更新时间:2023-10-16
我正在尝试编写一个函数,要求用户向控制台输入多个十六进制字符串,然后将这些字符串转换为位集。我希望函数使用指向位集的指针,以便位集存储在父函数中。由于不使用c++11,我将64位的位集拆分为两个十六进制转换操作。
void consoleDataInput(bitset<1> verbose, bitset<32>* addr, bitset<64>* wdata, bitset<8>* wdata_mask, bitset<1>* rdnwr)
{
cout << "enter 1 for read 0 for write : ";
cin >> *rdnwr;
string tempStr;
unsigned long tempVal;
istringstream tempIss;
// Input the addr in hex and convert to a bitset
cout << "enter addr in hex : ";
cin >> tempStr;
tempIss.str(tempStr);
tempIss >> hex >> tempVal;
*addr = tempVal;
// enter wdata and wdata_mask in hex and convert to bitsets
if (rdnwr[0] == 1)
{
*wdata = 0;
*wdata_mask = 0;
}
else
{
// wdata
bitset<32> tempBitset;
cout << "enter wdata in hex : ";
cin >> tempStr;
if (tempStr.length() > 8)
{
tempIss.str(tempStr.substr(0,tempStr.length()-8));
tempIss >> hex >> tempVal;
tempBitset = tempVal;
for (int i=31; i>=0; i--)
{
wdata[i+32] = tempBitset[i];
}
tempIss.str(tempStr.substr(tempStr.length()-8,tempStr.length()));
tempIss >> hex >> tempVal;
tempBitset = tempVal;
for (int i=32; i>=0; i--)
{
wdata[i] = tempBitset[i];
}
}
else
{
tempIss.str(tempStr);
tempIss >> hex >> tempVal;
tempBitset = tempVal;
for (int i=32; i>=0; i--)
{
wdata[i] = tempBitset[i];
}
}
// wdata_mask
cout << "enter wdata_mask in hex : ";
cin >> tempStr;
tempIss.str(tempStr);
tempIss >> hex >> tempVal;
*wdata_mask = tempVal;
}
当我尝试在代码块中使用GCC进行编译时,我会得到错误
C:DiolanDLNdemoApolloSPImain.cpp|202|error: no match for 'operator=' in '*(wdata + ((((sizetype)i) + 32u) * 8u)) = std::bitset<_Nb>::operator[](std::size_t) [with unsigned int _Nb = 32u; std::size_t = unsigned int](((std::size_t)i))'|
哪个突出显示了
wdata[i+32] = tempBitset[i];
据我所知,我不需要在wdata[i+32]
之前使用*运算符,因为[i+32]
充当它是指针的指示。
我不确定如何前进。=
运算符是用于位集的有效运算符,所以我不理解这个错误。
谢谢。
您的wdata实际上是一个指针,因此wdata[i+32]实际上相当于*(wdata+i+32),指向一个位集<64>。你用tempBitset[i]给这个比特集赋值,除非我弄错了,否则它是一个比特。
也就是说,您试图将单个位的值分配给整个位集。
我怀疑你想把一个比特集中的一个比特设置为另一个比特的值,在这种情况下,我认为你确实想要"*":
(*wdata)[i+32] = tempBitset[i];
大致意思是,取Bitset<64>,并将其位[i+32]设置为与tempBitset中的位集的位[i]相同的值。
相关文章:
- <<操作员在下面的行中工作
- C++ 与操作员不匹配<<
- 操作员C++的模棱两可的过载
- C++中>>操作员过载时出现问题?
- NaN 上的宇宙飞船操作员
- 比根<操作员
- SFINAE不能防止模棱两可的操作员过载吗?
- 什么是现实中的"endl"(或任何输出操纵器)?它是如何实现的,它如何与操作员<<一起工
- 为什么"delete"操作员给我访问权限冲突
- 为什么使操作员成为新的专用会打破 std::shared_ptr?
- 在这种情况下是私有的吗?试图使操作员<<过载
- C++操作员过载>>
- 是否有 C++20 浮点数的包装器,使我能够默认宇宙飞船操作员?
- 与异常处理程序中的操作员<<不匹配
- 复印作业操作员说明
- 友谊和操作员+=重载
- >操作员在比较两个C++容器时会怎么做?
- 与操作员比较两个计时时间点
- C++操作员订单评估
- 如何强制新操作员根据我的需要解释语句