[Insight-developers] help with template function problem
Aljaz Noe
noe@grasp.cis.upenn.edu
Thu, 18 Oct 2001 10:40:29 -0400
Looks like this is a bug in compiler related to this one:
http://support.microsoft.com/support/kb/articles/Q240/8/71.ASP?LN=EN-US&SD=g
n&FR=0&qry=template%20bug%20specification&rnk=4&src=DHCS_MSPSS_gn_SRCH&SPR=V
CC
The workaround in your case seems to be to declare a class and put in the
function as a static member. It looks wierd, but it works:
template<unsigned int VNumber>
class A {
public:
static void tfunction( )
{
unsigned int temp = VNumber;
std::cout << temp << std::endl;
}
};
Aljaz
> -----Original Message-----
> From: insight-developers-admin@public.kitware.com
> [mailto:insight-developers-admin@public.kitware.com]On Behalf Of Lydia
> Ng
> Sent: Wednesday, October 17, 2001 8:31 PM
> To: Insight-developers (E-mail)
> Subject: [Insight-developers] help with template function problem
>
>
> Hi,
>
> I am trying to interface between template world and non-template world.
> I have a problem with VC++ not being able to resolve
> a "unsigned int" template parameter. See code and results below.
>
> Does anyone know a fix/workaround to this for VC++?
>
> I also ran this test on Linux/gcc-2.96
> which doesn't have this problem.
>
> - Lydia
>
>
> =========Code=================================
> #include <iostream>
>
> template<unsigned int VNumber>
> void tfunction( )
> {
> unsigned int temp = VNumber;
> std::cout << temp << std::endl;
> }
>
> void function( unsigned int num )
> {
>
> switch (num)
> {
> case 1:
> tfunction<1>();
> break;
> case 2:
> tfunction<2>();
> break;
> case 3:
> tfunction<3>();
> break;
> case 4:
> tfunction<4>();
> break;
> }
>
> }
>
>
> int main()
> {
>
> for( unsigned int j = 1; j <= 4; j++ )
> {
> std::cout << "Following should be " << j << std::endl;
> function(j);
> }
> return 0;
> }
>
> ===============VC++ results==========================
> Following should be 1
> 4
> Following should be 2
> 4
> Following should be 3
> 4
> Following should be 4
> 4
>
> ==============Linux/gcc 2.96 results=================
> Following should be 1
> 1
> Following should be 2
> 2
> Following should be 3
> 3
> Following should be 4
> 4
>
> _______________________________________________
> Insight-developers mailing list
> Insight-developers@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-developers
>