Passing class template as a function parameter
This question is a result of my lack of understanding of a situation, so please bear if it sounds overly stupid.
I have a function in a class, like:
Class A {
void foo(int a, int b, ?)
{
----
}
}
The third parameter I want to pass, is a typed parameter like
classA<classB<double > > obj
Is this possible? If not, can anybody please suggest a 开发者_运维技巧workaround? I have just started reading about templates.
Thanks,
SayanDoesn't it work if you just put it there as a third parameter?
void foo(int a, int b, classA< classB<double> > obj) { ... }
If it's a complex type it might also be preferable to make it a const reference, to avoid unnecessary copying:
void foo(int a, int b, const classA< classB<double> > &obj) { ... }
You can use a member template:
Class A{
template <typename T>
void foo(int a, int b, T &c) {
}
}
精彩评论