Hi boys and girls,
I would like to propose new key word of the C++ language: "dynamictype". It is usefull in type-cast operation(s) such us:
int myvariable = 0;
dynamictype mytype;
mytype = typeof(float);
std::cout << dynamic_cast<mytype>(myvariable);
Here is a complex example:
//*
#include <iostream>
#include <string>
#include <iterator>
#include <algorithm>
#include <vector>
struct Example_1 {
int item1;
float item2;
};
struct Example_2 {
unsigned long item1;
int item2;
};
struct arrItem {
int key;
dynamictype Decl;
void* link;
};
int main()
{
arrItem *item = nullptr;
Example_1 *e1 = nullptr;
Example_2 *e2 = nullptr;
std::vector<arrItem> DataList;
// datovy typ 0 je Example_1
e1 = new Example_1();
e1->item1 = 101;
e1->item2 = (float)102.10;
DataList.push_back(arrItem());
DataList[0].key = 0;
DataList[0].typeDecl = typeof( Example_1 );
DataList[0].link = e1;
// datovy typ 1 je Example_2
e2 = new Example_2();
e2->item1 = 201;
e2->item2 = (int)202;
DataList.push_back(arrItem());
DataList[1].key = 1;
DataList[1].typeDecl = typeof( Example_2 );
DataList[0].link = e2;
for (int i = 0; i < (int)DataList.size(); i++) {
std::cout << "Example_1: key: "
<< DataList[i].key
<< "; item1: "
<< declarative_cast<DataList[i].typeDecl>(DataList[i].link)->item1;
<< "; item2: "
<< declarative_cast<DataList[i].typeDecl>(DataList[i].link)->item2;
std::cout << "\n";
}// for
delete(DataList[0].link);
DataList[0].link = nullptr;
delete(DataList[1].link);
DataList[1].link = nullptr;
DataList.clear();
}// int main()