jeudi 5 mai 2016

Outputting member type of a vector of types

I have a vector of unique_ptr<my_class> and would like to be able to pass to a function the member variable of this class I'd like to output. This vector is part of a class in itself.

For example I would like to

void my_top_class::output_member(sometype var_to_output, std::ofstream &out)
{
   // Iterate over the vector and output the member variable
   out << my_class->var_to_output << std::endl;
   // Or something similar
}

And then just do

 my_top_class.output_member(var1, file_out);
 my_top_class.output_member(var2, file_out);

At the moment I have a separate function for each member variable and this feels cumbersome

Aucun commentaire:

Enregistrer un commentaire