|
|
On Wed, 14 May 2008 18:23:54 +0200, Darren New <dne### [at] sanrrcom> wrote:
>
> *** Main2.cpp
>
> #include <A.h>
>
> void A::xx(int i) {
> cout << "Beta!\n";
> }
This will fail to compile, because you cannot redefine A::xx.
What I had in mind is something like this (untested, for obvious reasons):
// g.hpp
template <typename T> void g(T t) { /* Do whatever */ }
// end g.hpp
// main.cpp
export template <typename T> void f();
int main(){ f<int>(); }
// end main.cpp
// export.cpp
#include "g.hpp"
template <typename T> void f(){ g( T() ); }
// end export.cpp
Now make a small change to main.cpp:
// main.cpp
export template <typename T> void f();
#include "g.hpp"
template <> void g(int i) { /* Do something completely different */ }
int main(){ f<int>(); }
// end main.cpp
The instantiation context for the exported template changes, because there
is now an additional function participating in name lookup. In this case
the behaviour also changes because the new function is a better match.
Note that the signature of the exported template remains the same.
Note: I think the same should apply even if 'g' was not a template, but
GCC disagrees (tested without 'export' of course). VC does what I expect
though. I wish I knew which is right.
--
FE
Post a reply to this message
|
|