Hi Jerry,
From your code sample, it looks like you're trying to reinvent a technique known in C++ as "type erasure."
In today's C++, that would look like this:
struct arrItem {
int key;
UniquePrintable item1;
UniquePrintable item2;
};
int main()
{
std::vector<arrItem> DataList;
DataList.push_back({ 0, 101, 102.10 });
DataList.push_back({ 1, 201, 202 });
DataList.push_back({ 2, 301, "hello world" }); // just for fun
for (auto& [key, item1, item2] : DataList) {
std::cout << "key: " << key << "; item1: " << item1 << "; item2: " << item2 << "\n";
}
}
Here is the C++17 code all worked out, and executing correctly, on Godbolt.
I've omitted any equivalent of your `Example_1` and `Example_2` wrappers, because I didn't think they were important to the technique you were trying to show. But you can certainly see how to re-introduce them if you need to; and how to use type erasure for operations other than simple printing, as well.
HTH,
Arthur