Use the class template std::tuple declared in the header <tuple>. For example
#include <iostream>
#include <string>
#include <tuple>
int main()
{
std::tuple<std::string, int, double> t ={ "John", 12, 40.025 };
std::cout << std::get<0>( t ) << ", "
<< std::get<1>( t ) << ", "
<< std::get<2>( t ) << '\n';
std::cout << std::get<std::string>( t ) << ", "
<< std::get<int>( t ) << ", "
<< std::get<double>( t ) << '\n';
return 0;
}
The program output is
John, 12, 40.025
John, 12, 40.025
And you may use a container of elements with this type as for example an array because the listed types in the tuple are default constructible.
For example
#include <iostream>
#include <string>
#include <tuple>
int main()
{
std::tuple<std::string, int, double> t[1];
t[0] = { "John", 12, 40.025 };
std::cout << std::get<0>( t[0] ) << ", "
<< std::get<1>( t[0] ) << ", "
<< std::get<2>( t[0] ) << '\n';
std::cout << std::get<std::string>( t[0] ) << ", "
<< std::get<int>( t[0] ) << ", "
<< std::get<double>( t[0] ) << '\n';
return 0;
}
As an alternative you can define your own compound type (class or structure) that will contain sub-objects of required types.
std::tuple<string,int,double>, andget<N>to access the Nth tuple element. You can store these tuples in anarrayorvector.std::vector<mystruct>where mystuct is a class or struct that contains your 3 different types.