C++ 中的位集使用VS2010
我不知道我在这里做错了什么,希望有人能启发我。
我有一个类Flags
,这是一个极其简化的版本,但我
class Flags
{
private:
//List of 8 bits
std::bitset<8> _P;
public:
Flags();
}
在构造函数上声明了一个位集,我将其初始化为
Flags::Flags()
: _P(32ul)
{}
但它不会编译并给我错误
错误 C2668:“std::bitset<_Bits>::bitset”:不明确的调用 重载函数
这是在 VS2010 SP1 64 位中编译的,但作为 32 位程序
编辑
接受的答案是针对上述内容,但作为旁注,任何人都可以解释为什么在使用默认构造函数(应将它们全部初始化为零)时,它们并不全部设置为零?
_p.to_ulong()
返回1390560944 和 _p 看起来像
[8](0,0,0,0,1,1,0,1)
I can't figure out if I'm doing anything wrong here, hopefully someone here can enlighten me.
I have a class Flags
, this is an extremely simplified version but I declare a bitset
class Flags
{
private:
//List of 8 bits
std::bitset<8> _P;
public:
Flags();
}
On my constructor I initialise it as
Flags::Flags()
: _P(32ul)
{}
But it won't compile and gives me the error
error C2668: 'std::bitset<_Bits>::bitset' : ambiguous call to
overloaded function
This is compiled in VS2010 SP1 64 bit but as a 32bit program
EDIT
Accepted answer is for the above but as a side note could anyone explain why when using the default constructor (which should initialise them all to zero's) they aren't all set to zero's?
_p.to_ulong()
returns 1390560944
and _p looks like
[8](0,0,0,0,1,1,0,1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据http://connect.microsoft.com/VisualStudio/feedback/details/532897/problems-constructing-a-bitset-from-an-unsigned-long-in-the-vc-rc
另请注意,以
_
和大写字母开头的标识符是为实现而保留的,在您的程序中使用是非法的。编辑:根据解决方法页面(如果我没读错的话),解决方法是将您的值转换为
unsigned long long
而不是unsigned long
。It's a bug in VC according to http://connect.microsoft.com/VisualStudio/feedback/details/532897/problems-constructing-a-bitset-from-an-unsigned-long-in-the-vc-rc
Also note that identifiers starting with
_
and a capital letter are reserved for the implementation and illegal to use in your program.EDIT: According to the workaround page (if I read it right), the workaround is to cast your value to
unsigned long long
instead ofunsigned long
.