473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Template instantiation problems

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
}

Nov 16 '05 #1
1 1193
Lewis Baker wrote:
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<T>::P x = X;
}

// 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
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dave | last post by:
Hello all, Consider this function template definition: template<typename T> void foo(T) {} If foo is never called, this template will never be instantiated. Now consider this explicit...
7
by: Drew McCormack | last post by:
I have a C++ template class which contains a static variable whose construction registers the class with a map. Something like this: template <typename T> class M { static Registrar<M>...
4
by: Dave | last post by:
Hello all, Consider this template: template <typename T> void foo(T bar) {...} Here are three ways to instantiate this: 1.
12
by: mlimber | last post by:
This is a repost (with slight modifications) from comp.lang.c++.moderated in an effort to get some response. I am using Loki's Factory as presented in _Modern C++ Design_ for message passing in...
2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
3
by: sks | last post by:
Hello all Is the usage of extern keyword valid for telling the compiler to NOT instantiate a template and to link it from an another binary? For example: Suppose module A's binary contains a...
8
by: Ole Nielsby | last post by:
I want to create (with new) and delete a forward declared class. (I'll call them Zorgs here - the real-life Zorks are platform-dependent objects (mutexes, timestamps etc.) used by a...
0
by: mqrk | last post by:
On Sep 12, 4:58 am, dizzy <di...@roedu.netwrote: I don't know that there is any way around this with g++ and ld. I find that surprising, but that may well be. Have you tried using explicit...
4
by: Pallav singh | last post by:
Hi All, i am getting error during explicit function Instantiation for a class Template if i do explicit Instantiation of class it work and all function symbol i get in object file But if i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.