|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - (template) overload resolution
Here is a small test-case:
#include <stdio.h>
template<class T>
int f(T *)
{
return 0;
}
template<class T>
int f(const T *)
{
return 1;
}
int g(char *)
{
return 0;
}
int g(const char *)
{
return 1;
}
template<class T>
int h(T *, T *)
{
return 0;
}
template<class T>
int h(const T *, T *)
{
return 1;
}
int i(char *, char *)
{
return 0;
}
int i(const char *, char *)
{
return 1;
}
int main(int argc, char *argv[])
{
char a = 0;
printf("%d\n", f(&a));
printf("%d\n", g(&a));
printf("%d\n", h(&a, &a));
printf("%d\n", i(&a, &a));
return 0;
}
I would expect to get four times "0" (and that's what I get with gcc
3.0.1/2.95.3 and Watcom 11.0c), but DM chooses "int f(const T *)" instead of
"int f(T *)" and doesn't like the h function template at all:
Error: ambiguous reference to symbol
Had: h(T*,T*)
and: h(const T*,T*)
bye, Christof
--
http://cmeerw.cjb.net Jabber: cmeerw jabber.at
mailto cmeerw at web.de ICQ: 93773535, Yahoo!: cmeerw
...and what have you contributed to the Net?
Oct 22 2001
Here is a somewhat related test-case:
struct A
{ };
struct B
: public A
{ };
template<class T>
int f(T a, const A&)
{
return 1;
}
template<class T>
int f(T a, const B&)
{
return 0;
}
int main(int argc, char *argv[])
{
char c = 0;
return f(c, B());
// Error: ambiguous reference to symbol
// Had: f(T,const A&)
// and: f(T,const B&)
}
bye, Christof
--
http://cmeerw.cjb.net Jabber: cmeerw jabber.at
mailto cmeerw at web.de
...and what have you contributed to the Net?
Oct 31 2001
Got it! "Christof Meerwald" <cmeerw web.de> wrote in message news:9roldc$1n0a$1 digitaldaemon.com... Oct 31 2001
Any chance this will be fixed any time soon? (it doesn't work with DMC 8.29.6n beta) I am asking because STLport 4.5.3 uses these constructs quite often. On Wed, 31 Oct 2001 10:56:44 +0000 (UTC), Christof Meerwald wrote: Jul 07 2002
|