c++ - template arguments
- Christof Meerwald <cmeerw web.de> Dec 14 2002
- Christof Meerwald <cmeerw web.de> Dec 22 2002
See 14.3 Template arguments [temp.arg], paragraph 2, of the C++ standard:
#include <stdio.h>
template<class T> int f()
{
return 0;
}
template<int I> int f()
{
return 1;
}
int main()
{
printf("%d\n", f<int()>()); // int() is a type-id: call the first f()
}
DM calls the second f().
bye, Christof
--
http://cmeerw.org JID: cmeerw jabber.at
mailto cmeerw at web.de
...and what have you contributed to the Net?
Dec 14 2002
template<typename T>
struct A
{
A(T *t)
: t(t)
{ }
int f()
{
return t(0);
}
T *t;
};
int f(int x)
{
return x;
}
int main()
{
A<int(int)> a(f);
// Error: ')' expected
a.f();
return 0;
}
I guess this should also be allowed as a template argument (it's at least
the preferred syntax for Boost.Function).
bye, Christof
--
http://cmeerw.org JID: cmeerw jabber.at
mailto cmeerw at web.de
...and what have you contributed to the Net?
Dec 22 2002








Christof Meerwald <cmeerw web.de>