Topic: Function template matching
Author: "Steve R. Karmesin" <ssr@cacr.caltech.edu>
Date: 1996/11/22 Raw View
I have a question about what the standard requires for matching a
certain type of function template.
Suppose you have a class with nested classes:
class A
{
public:
class B {};
class C {};
};
And you then write functions like:
void f(A::B ab) {}
void f(A::C ac) {}
int main()
{
A::B a;
f(a);
}
Then all is well. If you want to template these two, all is not well:
template<class T> void f(A::T at) {}
In fact things seem to be unwell in a very bizarre manner. From the
Kuck and Associates C++ compiler (the closest to the draft standard that
I'm aware of) I get the error messages:
"nest.cpp", line 13: error: "f" is not a function or static data member
template<class T> void f(A::T at) {}
^
"nest.cpp", line 13: error: expected a ";"
template<class T> void f(A::T at) {}
^
The SGI C++ compiler (7.1beta) give similar errors.
It looks like it is parsing this expression completely differently from
how I would expect.
Is this an aspect of template definitions that is addressed in the
standard?
--
Steve R. Karmesin
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1996/11/23 Raw View
Steve R Karmesin writes:
> class A
> {
> public:
> class B {};
> class C {};
> };
[snip]
> template<class T> void f(A::T at) {}
You should think of T as a type, not as a class name. You would not
refer to such a template as f<B> or f<C>, since B and C are not types.
Instead, you should declare:
template <class T> void f(T at) {}
then use f<A::B> and f<A::C>.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br
Universidade Estadual de Campinas, SP, Brasil
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]