B
Bit Byter
I just realized that I cant use a union in an initialization list (or
at least not the way I tried to use it).
This is what I did:
class ValueObject
{
public:
ValueObject();
ValueObject(const ValueObject&);
ValueObject& operatr= (const ValueObject&);
private:
union Item { int i, double d, char s[8]} m_item ;
enum { integer, Double, String } m_type ;
};
//impl:
ValueObject():m_type(Integer), m_item.i(0) //<- compiler complains
{}
ValueObject():m_type(Integer)//<- compiler ok with this - why?
{m_item.i(0);}
at least not the way I tried to use it).
This is what I did:
class ValueObject
{
public:
ValueObject();
ValueObject(const ValueObject&);
ValueObject& operatr= (const ValueObject&);
private:
union Item { int i, double d, char s[8]} m_item ;
enum { integer, Double, String } m_type ;
};
//impl:
ValueObject():m_type(Integer), m_item.i(0) //<- compiler complains
{}
ValueObject():m_type(Integer)//<- compiler ok with this - why?
{m_item.i(0);}