Hi,
I found a bit of a weirdo using Intel 4.5 compiler & I've seen similar bad
stuff in VC6. I don't know if it is a language 'feature' or a bug in the
compiler's template handling - the compilers are old.
Basically I have a template function (as a member in a class) with void
return & argument. To use the function you have to explicitly tell the
compiler what type - or the compiler errors (reasonable as it can't
determine the type!). The linked program then uses the first type
encountered for all links to that function (i.e. _same_ address)
regardless
of they type provided! To fix it, if I declare a return type of the
template
type instead of void, it links the explicitly defined function correctly!
Is
this a bug with "template<class T> void fn(void) hadnling by this compiler
or a language feature in all C++ compilers? (feels like a name
mangling/linker bug to me)
Chris
e.g.
HEADER
class foo
{
public:
void SomeFN();
template<class T> void Broken();
template<class T> T Works();
};
template<class T> void Broken()
{
assert(sizeof(double) == sizeof(T)); // some code which uses T
}
template<class T> T Works()
{
assert(sizeof(double) == sizeof(T)); // some code which uses T
return 1;
}
C++
void foo:SomeFN()
{
Broken<float>(); // ok, type is float in expanded fn
Broken<double>(); // broken, type is also float!
Works<float>(); // ok, type is float
Works<double>(); // ok, type is double
}
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|