Everything in this program produces the correct results except the part
dealing with the RealList. The "for" loop does not output the values that
were input to the ALL[3].RealList. What is the correct syntax to for this?
Thanks
#include <stdio.h>
#include <string>
#include <vector>
union AllType {
int Int;
double Real;
std::string* Text;
std::vector<double>* RealList;
};
void main()
{
std::vector<AllType> ALL;
ALL.reserve(10);
printf("sizeof(ALL)--->%d\n", sizeof(ALL));
printf("sizeof(AllType)--->%d\n", sizeof(AllType));
ALL[0].Int = 31415926;
ALL[1].Real = 3.1415926;
ALL[2].Text = new std::string("Hell Oh Whirled");
ALL[3].RealList = new std::vector<double>;
ALL[3].RealList->reserve(3);
ALL[3].RealList->push_back(123.0);
ALL[3].RealList->push_back(456.0);
ALL[3].RealList->push_back(789.0);
printf("%d\n", ALL[0].Int);
printf("%f\n", ALL[1].Real);
printf("%s\n", ALL[2].Text->c_str());
for (unsigned int N = 0; N < ALL[3].RealList->size(); N++)
printf("%d) %f\n", N, ALL[3].RealList[N]);
}