我有一個向量unique_ptr<my_class>
,並希望能夠傳遞給我想要輸出的這個類的成員變量的函數。這個向量本身就是一個類的一部分。類型向量的輸出成員類型
比如我想
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
}
然後就去做
my_top_class.output_member(var1, file_out);
my_top_class.output_member(var2, file_out);
此刻,我對每一個成員變量獨立的功能,這樣的感覺很麻煩
他已經有一個'my_object'不過,第二PARAM也許應該是一個outstream。不錯的解決方案。 –
@GillBates正如我所寫,它只是一個例子。謝謝。 – Constructor