Can I use a union declaration in a constructor ?

Hello,

I am trying to learn C++, I used to work with C

I have a question about constructors, lets suppose that we have a file C.cpp and

another file C.hpp, the second one contains the definition of the first one

constructors,

I need to have a variable var in this class which is a union of integer, double,

char,

How to introduce that in the hpp file, is it correct to do it ??

Thanks.
You mean like
1
2
3
4
5
6
7
8
class foo {
private:
union uni {
   int foo;
   double dfoo;
   char cfoo;
}
};

?
Topic archived. No new replies allowed.