template should work

I created my very first template. I had the first 2 parts by themselves and they worked fine. I added a third and now the first doesn't work. What am I doing wrong?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;

template <class T, class U, class V>
T mult(T a, U b){return (a*b);}//worked fine
template <class T, class U, class V>
T mult(T a, U b, V c){return ((a*b)*c);}//worked fine
template <class T, class U, class V, class W>
T mult(T a, U b, V c, W d){return (((a*b)*c)*d);}//compiler is'nt complaining about this

int main()
{
    double i;
    cout << mult(2,2)//compiler now says no matching function
    << "\t"
    << mult(0.5,2,0.5)//this still works fine
    << endl;

    return 0;
}
Last edited on
There is no matching function for mult(2,2) - You are probably thinking that this one
1
2
template <class T, class U, class V>
T mult(T a, U b){return (a*b);}

would match.
But you will notice that you have not accounted for the template parameter V.
Last edited on
Dude.... i feel like such a moron. At least I would if I hadn't been up for something like 20 hours strait. I'm at 25 hours now. LOL Thanks guestgulkan. :o)
Last edited on
Topic archived. No new replies allowed.