Re: template keyword needed
"George" <George@discussions.microsoft.com> wrote in message
news:A0D1D5D6-83B7-4B74-B39F-C82EBA6286C6@microsoft.com
Any comments to my previous points quoted below? Correct or not?
I haven't seen any new points made that would require a comment. You are
just repeating what I've already said.
For
example, for the following code, I think nothing inside function f is
dependent on template parameter T, right?
template <class T> void f (vector<T>& v)
{
for (int i = 0; i < v.size(); i++)
{
cout << v [i] << endl;
}
}
There are three dependent names here, I believe: size, operator[] and
operator< (the one in the expression i < v.size(), since you don't know
what size() may return). You cannot determine what declarations these
names refer to until you know T, since there might, in principle, be a
specialization of std::vector for some type that defines these names
differently than the primary template, or even not at all.
In short, whether or not template function can be instantised is not
dependent on whether there is any template parameter dependent names
inside the function, right?
Correct. In C++, the term "dependent name" has specific meaning related
to the process of name lookup, and has little to do with template
instantiation.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925