template <class T1, ...>
f(1, 1.0, "1") does not match template <class t1,class t2>f(t1 a1, t2 a2, t3 a3) { . . . }
template <class t>
inline t max(t v1, t v2) {
return v1 > v2 ? v1 : v2;
}
void fint(int x, int y) {
int m = max(x, y);
}
void fdbl(double x, double y) {
double m = max(x, y);
}
void fstr(std::string & x, std::string & y) {
std::string m = max(x, y);
}
template <class t>
t * oops(int i) {
i++;
return new t;
}
void f(void) {
int * ip = oops(1);
}
template <class t>
void oops(t i, t j) {
// whatever
}
void f(void) {
int i = 3;
unsigned j = 4;
oops(i, j)
}
consts are another source of problems, particularly in the stl
template <class Etype> class stack {. . .};
stack<int> istk;
template prefix
template prefix
template <typename Etype, int size>
class stack {
// and so on
};
void f(void) {
stack istack;
// and so on
}
template <typename Etype = int, int size = 100>
class stack {
// and so on
};
void f(void) {
stack cstack;
stack sstack;
stack<> istack;
// and so on
}
This page last modified on 27 February 2001.