Re: MSDN template sample
Ben Voigt [C++ MVP] <rbv@nospam.nospam> wrote:
Here is a slight variation that illustrates the problem with
compiling only (no need to run the executable).
It compiles fine with http://www.comeaucomputing.com/tryitout/ because
f(char) is not called, so no definition is needed. However MSVC
would give an undefined external error forcing you to uncomment the
body of f(char).
<code>
#include <stdio.h>
namespace N {
void f(int);
}
template <class T> void g(T) {
N::f('a'); // calls f(char) should call f(int)
}
namespace N {
void f(char);
}
int main() {
g('c');
}
namespace N {
void f(int) { puts("f(int)\n");}
//void f(char) { puts("f(char)\n");}
}
</code>
It compiles fine with http://www.comeaucomputing.com/tryitout/ even if
you move the declaration of f(char) up where the definition of g() can
see it, or if you remove the implementation of f(int). Comeau Online
compiles, but doesn't link.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925