#include typedef unsigned int* universel; /* Crée un type nommé "universel" équivalent à un pointeur sur un entier non-signé (tu peux mettre n'importe quel autre type de pointeur */ int main() { // Trois variables de types différents : std::string texte = "Un texte simple"; int entier = 7; double decimal = 6.3; // Leur pointeurs respectifs : std::string *ptr_texte = &texte; int *ptr_entier = &entier; double *ptr_decimal = &decimal; universel tableau[3]; // Le fameux tableau de type universel // Pour remplir ce tableau il faut transtyper toutes les valeurs qui y rentre : tableau[1] = (universel)ptr_texte; tableau[2] = (universel)ptr_entier; tableau[3] = (universel)ptr_decimal; std::cout << "Universel[1] = " << *tableau[1] << "\n"; // Affiche un nombre quelconque std::cout << "Universel[1] = " << *(string*)tableau[1] << "\n\n"; // Affiche "Un texte simple std::cout << "Universel[2] = " << *tableau[2] << "\n"; // Affiche 7 std::cout << "Universel[2] = " << *(int*)tableau[2] << "\n\n"; // Affiche 7 std::cout << "Universel[3] = " << *tableau[3] << "\n"; // Affiche un nombre quelconque std::cout << "Universel[3] = " << *(double*)tableau[3] << "\n"; // Affiche 6.3 return 0; }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questiontemplate <typename FirstType, typename SecondType, typename ThirdType> struct Row { FirstType _a; SecondType _b; ThirdType _c; }; Row row(1, 1.0, 54.56); Row<std::string, int, int> row("test", 5, 4); // Tu peux ensuite faire un std::vector<Row<std::string, int, int> > ou std::list<Row<std::string, int, int> > // et un std::vector<Row > ou std::list<Row >
std::vector > std::vector > std::vector > std::vector > // etc...