By combining MaheshRathi & Jyrixx ideas I have given a sample program. It may fulfill your requirement.
#include <iostream>
#include <cstring>
using namespace std;
typedef union
{
int iData;
double dData;
char sData[100];
}DATA;
class stackUnion
{
private :
struct
{
unsigned char type;
DATA value;
} mVar[5];
int index;
public :
stackUnion();
void push(int);
void push(double);
void push(char *);
DATA * pop();
};
stackUnion :: stackUnion()
{
index = 0;
cout << "stackUnion Constructor" << endl;
}
void stackUnion :: push(int iArg)
{
if(index >= 4)
{
cout << "Error push : stack full :" << endl;
return;
}
mVar[index].type = 0;
mVar[index++].value.iData = iArg;
}
void stackUnion :: push(double dArg)
{
if(index >= 4)
{
cout << "Error push : stack full" << endl;
return;
}
mVar[index].type = 1;
mVar[index++].value.dData = dArg;
};
void stackUnion :: push(char *sArg)
{
if(index >= 4)
{
cout << "Error push : stack full" << endl;
return;
}
mVar[index].type = 2;
strcpy(mVar[index++].value.sData, sArg);
}
DATA * stackUnion :: pop()
{
index--;
if(index < 0)
{
cout << "Error push : Empty statck" << endl;
return 0;
}
return & mVar[index].value;
}
int main()
{
stackUnion Stack;
Stack.push(10);
Stack.push(7.3);
Stack.push("Testing"

;
Stack.push("Maniraja S"

;
Stack.push("smara"

;
Stack.push("Exit"

;
cout << "String data : " << ( (char*) Stack.pop()) << endl;
cout << "String data : " << ( (char*) Stack.pop()) << endl;
cout << "Double data : " << *( (double *) Stack.pop()) << endl;
cout << "int data : " << *( (int *) Stack.pop()) << endl;
cout << "Null data : " << Stack.pop() << endl;
return 0;
}
If you want to have information about the stored data int Stack object then you have to return the struct variable from pop() instead of union variable (given that you have to declare the struct out side the class).
--Maniraja S