[Insight-developers] help with template function problem

Lydia Ng lng@insightful.com
Wed, 17 Oct 2001 17:30:45 -0700


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