mardi 14 avril 2015

Template function taking class as parameter

I want to write something like that:



template <class T>
void write(my_out_stream &output_stream, T &data)
{

}

class A
{
public:
int a;
int b;
};

class B
{
public:
int c;
}

int main()
{
A a;
B b;
my_out_stream mos;

write(mos, a);
write(mos, b);

return 0;
}


Is it possible? If not, how I should create function write, if I don't know, which classes will be use its.


Note, that I can not change call way (write(mos, a)). I am able to to change only signature of write.


Aucun commentaire:

Enregistrer un commentaire