Topic: New template rules
Author: b91926@fsgi01.fnal.gov (David Sachs)
Date: 27 May 1994 17:07:30 -0500 Raw View
The C++ standards committee, has recently decreed
that in templates, function calls are evaluated for
overloading as of the time the template is declared
unless the call "depends on" a template argument.
What is the proper output of the following horrible example?
#include <iostream.h>
void f(float x) {cout << "float " << x << endl;}
template <class T> struct B
{
void f(int x) {cout << "member int " << x << endl;}
};
template <class T> struct D : B<T>
{
void g() {f(1);} // Does this depend on T???
}
struct B<int> // specialization - does not have an f()
{
};
// The following overloaded function is not known at the point
// where D is declared.
void f(int x) {cout << "int " << x <<endl;}
B<int> z;
int main()
{
z.g(); // produces what????
return 0;
}
Please excuse typos.
Author: b91926@fsgi01.fnal.gov (David Sachs)
Date: 27 May 1994 19:48:02 -0500 Raw View
In my previous article I put in a typo. The
declaration should read
D<int> z;
rather than
B<int> z;