Q:

Unresolved constructor for bitset

typedef unsigned long int  uint32;

uint32 c = uint32(-1) - 5;
std::bitset<32> y(uint32(c));

This code yields:

FeatureTest.obj : error LNK2019: unresolved external symbol "class
  std::bitset<32> __cdecl y(unsigned long)"
  (?y@@YA?AV?$bitset@$0CA@@std@@K@Z) referenced in function _main

How can i do it for unsigned long?
EIDT: Looks like this is a bug in VS 2010 - https://connect.microsoft.com/VisualStudio/feedback/details/532897/problems-constructing-a-bitset-from-an-unsigned-long-in-the-vc-rc

A:

As the error message indicates, the compiler is parsing your code as declaring a function y. This is an instance of the Most Vexing Parse problem. In this particular case, you don't need a cast at all, c is already the right type. But if you needed a cast, you could work around it by replacing uint32(c) with (uint32)c or better static_cast<uint32>(c).

