Template instantiation problems

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


}
 
C

Carl Daniel [VC++ MVP]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top