S
SteveM
The general consensus I am getting is that nobody really uses unions
much (engineers here at work) but this is an academic exercise for me
so I am looking for an answer (I know there may be better ways to do
this ;-) ).
What I need to know is how to write the function prototype and the
function definition for a function that returns a union.
For example: Here is a class for a double linked list in which variable
data is going to be stored. I decided a union would be a good way to go
class Node
{
public:
Node();
Node * getPrev();
Node * getNext();
Node * appendNode();
void storeVal();
int getVal(Type);
char getVal(Type);
union getVal(); <<<< I know this is wrong thats why I need help
private:
Node * nextNode;
Node * prevNode;
Node * currentNode;
union
{
int intVal;
char charVal;
char * strVal;
};
};
in the implementation file I have
this:
union Node::getVal()
{
return strVal;
}
All I am asking is 1.) is it possible to return a union type
and 2.) if so how do you instrument it in code (declaration and
definition)
Thanks one and all for your help
SteveM
much (engineers here at work) but this is an academic exercise for me
so I am looking for an answer (I know there may be better ways to do
this ;-) ).
What I need to know is how to write the function prototype and the
function definition for a function that returns a union.
For example: Here is a class for a double linked list in which variable
data is going to be stored. I decided a union would be a good way to go
class Node
{
public:
Node();
Node * getPrev();
Node * getNext();
Node * appendNode();
void storeVal();
int getVal(Type);
char getVal(Type);
union getVal(); <<<< I know this is wrong thats why I need help
private:
Node * nextNode;
Node * prevNode;
Node * currentNode;
union
{
int intVal;
char charVal;
char * strVal;
};
};
in the implementation file I have
this:
union Node::getVal()
{
return strVal;
}
All I am asking is 1.) is it possible to return a union type
and 2.) if so how do you instrument it in code (declaration and
definition)
Thanks one and all for your help
SteveM