tags:

views:

54

answers:

2

Hi,

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,
Sayan

+4  A: 

Doesn'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) { ... }
sth
That was the first thing I tried, but the compiler complained that Class A is not a type, and hence I thought whether this syntax is okay. I now think that I am getting the error because of something else, just wanted to make sure I wasn't wrong on how I thought it would be. Many thanks for confirming.
Sayan
+1  A: 

You can use a member template:

Class A{

template <typename T>
void foo(int a, int b, T &c) {

    }
}
MarkD
Why would he/she need a member template?
Noah Roberts
I think I must have misunderstood the question. (I was interpreting the ? in the third parameter, as being an unknown type). My bad.
MarkD