>
fe**********@hotmail.comwrote:
I would wery much like this to work:
@code start
#include <iostream>
#include <bitset>
const unsigned short size = 2; // 2^<unsigned int> //
union V {
char c[(size*size*size)/8];
std::bitset<size*size*size> b;
} v;
@code end
The compiler wont accept it and i cant accept that ;-)
A far as im concersed a bitset is just a number of bits and it
shouldnt be a problem, however it is and im in great need of a solution.
compiler error: "member std::bitset<8u> V::b' with constuctor
not allowed in union"
Dear Sir, C++ union is a little bit too useless because it supports
only POD types. In your case you have std::bitset which is not a POD
type. There are many solutions, but the best I can recommend is to
use "boost::variant". Variant template in boost is a safe, generic,
stack-based discriminated union container, offering a simple solution
for manipulating an object from a heterogeneous set of types in a
uniform manner. That's what you need. Read more at
http://www.boost.org/doc/html/variant.html
Wish best regards,
Vladislav Lazarenko.