bitsets in C++ using VS2010

好久不见. 提交于 2019-12-01 21:46:48

问题


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)

回答1:


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 of unsigned long.



来源:https://stackoverflow.com/questions/6947322/bitsets-in-c-using-vs2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!