[Insight-developers] help with template function problem
Luis Ibanez
ibanez@choroid.cs.unc.edu
Thu, 18 Oct 2001 06:24:36 -0400 (EDT)
Hi Lydia,
maybe adding an enum could
help to wake VC++ up
template<unsigned int VNumber>
void tfunction( )
{
static enum { WakeUpVC = VNumber };
unsigned int temp = WakeUpVC;
std::cout << temp << std::endl;
}
Luis
-------------------
On Wed, 17 Oct 2001, Lydia Ng wrote:
> 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
>
--
Luis Ibanez CB#: 7060
Research Assistan Professor phone: (919) 843 5436
Division of Neurosurgery fax: (919) 966 6627
University of North Carolina at Chapel Hill email: ibanez@cs.unc.edu
Chapel Hill, NC 27599-7060 http://www.cs.unc.edu/~ibanez