By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,134 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

Can a successfully compileable template definition fail on instantiation?

P: n/a
Assuming of course that the instantiation statement is 100% ok.
As a matter of fact, that very instantiation passes successfuly on VC++ 7.1
(and Borland) but since I was suspicious that it was OK there "more by luck
than brain", I checked the same on Linux\GNU were the instantiation failed.

This question is more for people who know well the C++ ISO standard, the
chapter on templates. My hunch is that the problem is with the language spec.

Thanks
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
David wrote:
Assuming of course that the instantiation statement is 100% ok.
As a matter of fact, that very instantiation passes successfuly on VC++ 7.1 (and Borland) but since I was suspicious that it was OK there "more by luck than brain", I checked the same on Linux\GNU were the instantiation failed.
This question is more for people who know well the C++ ISO standard, the
chapter on templates. My hunch is that the problem is with the

language spec.

Why don't you just post some minimal piece of code that reproduces the
problem?

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #2

P: n/a
ag******@yahoo.com (David) wrote in message news:<b6**************************@posting.google. com>...
Assuming of course that the instantiation statement is 100% ok.
As a matter of fact, that very instantiation passes successfuly on VC++ 7.1
(and Borland) but since I was suspicious that it was OK there "more by luck
than brain", I checked the same on Linux\GNU were the instantiation failed.


Yes, and this is in fact a very common technique. For instance,
std::vector<T>::vector( size_type, T const& = T(), {default allocator} )

It is impossible to instantiate this member when only the size_type
argument is provided and T doesn't have an accessible default ctor.

Basically templates compile if there is at least one set of arguments
for which they can be instantiated. The reverse is not true; some
errors are too hard to detect without instantiating.

E.g. a template with unsigned integer parameters A,B,C and N that
could only compile if A^(N+3)+B^(N+3)==C^(N+3). A compiler may
reject this, because there is no set of arguments for which this holds
but it isn't required to be aware of the proof to Fermats theorem.
It may instead reject every attempt to instantiate.

Regards,
Michiel Salters
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.