Template instantiation problems

  • Thread starter Thread starter Lewis Baker
  • Start date Start date
L

Lewis Baker

I am having some template problems in VC7.1


The following code should compile fine but I get the error:


'warning C4667: 'void F(Traits<T>::P)' : no function
template defined that matches forced instantiation'




However if I instantiate the function implicitly by using
it in some code then everything seems to work.




Any clues or is this a compiler bug?




Regards,


Lewis




---- Code below ----




// Traits class


template<class T>


class Traits


{


public:


typedef T* P;


};




// Template function declaration


template<class T> void F( typename Traits<T>::P );




// Template function definition


template<class T>


void F( typename Traits<T>::P X )


{


Traits<T>::P x = X;


}




// Explicitly instantiate function


template void F( Traits<int>::P ); // <-- Error here




// Implicitly instantiate function


void UseF()


{


int a;


F<int>( &a ); // <-- No problems


}
 
Lewis said:
I am having some template problems in VC7.1
The following code should compile fine but I get the error:

The code should not compile, according to the C++ standard.
'warning C4667: 'void F(Traits<T>::P)' : no function
template defined that matches forced instantiation'

However if I instantiate the function implicitly by using
it in some code then everything seems to work.

Any clues or is this a compiler bug?

The code's not required to compile.
Regards,

Lewis

---- Code below ----
// Traits class
template<class T>
class Traits
{
public:
typedef T* P;
};

// Template function declaration
template<class T> void F( typename Traits<T>::P );

// Template function definition
template<class T>
void F( typename Traits<T>::P X )
{
Traits<T>::P x = X;

This should be

typename Traits said:
}

// Explicitly instantiate function
template void F( Traits<int>::P ); // <-- Error here

This is a non-deduced context. The compiler is unable to deduce the
template arguments based on these formal types.
// Implicitly instantiate function
void UseF()
{
int a;
F<int>( &a ); // <-- No problems
}

-cd
 
Back
Top