POV-Ray : Newsgroups : povray.off-topic : A question about Java generics (not a flame) : Re: A question about Java generics (not a flame) Server Time
7 Sep 2024 23:28:23 EDT (-0400)
  Re: A question about Java generics (not a flame)  
From: Fredrik Eriksson
Date: 14 May 2008 15:07:05
Message: <op.ua5rd2kh7bxctx@e6600.bredbandsbolaget.se>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.