Topic: templates - compiler error


Author: asAchults@visiSon.Eee.ethz.ch ("Anton S.")
Date: Tue, 29 Apr 2003 06:29:21 +0000 (UTC)
Raw View
sks_cpp wrote:
> template<typename A, typename B, typename C> void determineType(A, B, C)
> {
>     determine(A);  // It doesn't allow me to do this ?? why ??
> }


"A" in Your case is a type and not a variable.

What You need to do is:

template<typename A, typename B, typename C> void determineType(A a, B, C)
{
     determine(a);  // Use variable instead of type.
}


--
Please remove the capital letters from my email address.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: sksjava@hotmail.com ("sks_cpp")
Date: Mon, 28 Apr 2003 17:03:37 +0000 (UTC)
Raw View
#include <iostream>

using namespace std;

template< typename A > void determine( A )
{
    cout << "Not an int or a double\n";
}
template<> void determine<int>( int a )
{
    cout << "It's an int\n";
}
template<> void determine<double>( double a )
{
    cout << "It's a double\n";
}
template<typename A, typename B, typename C> void determineType(A, B, C)
{
    determine(A);  // It doesn't allow me to do this ?? why ??
}


int main()
{
    int a = 1;
    double b = 2.0;
    char c = 'a';

    determine(a);  // works fine
    determine(b);  // works fine
    determine(c);  // works fine

    determineType(a,b,c);  // doesn't work ??

 return 0;
}




---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]