
On 11/2/07, Dean Michael Berris <mikhailberis@gmail.com> wrote:
On 11/2/07, gchen <chengang31@gmail.com> wrote:
That is because you need to know what signatures the overload instance will support. In C++, you have no way of modifying a type at runtime -- and that's why what you propose is nearly impossible if not impractical to implement.
I would say it's impossible in C++ ;-) I stumbled on this during my little object factory development. The reason it is impossible is that templates do not change the type of already defined variables. In your example: overload<> f; // after compiler processes the above statement the type of 'f' has been exactly //defined, 'f' is no more a template after compilation of this line! so type of 'f' // cannot be changed again but... f.set(&int_sum); // ...it should be because the above line would change the type of 'f' as soon as // compiler process the above statement. So the reason the above is impossible is that: - After compilation of a template variable definition, the variable assumes a fixed, complete type. - In C++ type of a variable cannot be changed once the variable has been defined. Hope this is clear. Marco