Re: umm... something... template(s)... something else... pointer(s)... and such... 0.o yah, I'm hopeless and clueless o.0

From: John Harrison (john_andronicus_at_hotmail.com)
Date: 10/11/04


Date: Mon, 11 Oct 2004 13:04:11 +0100


[snip]

> What's really important to me is what this template stuff ends up
> doing... in any sort of general way... it's hard to get to abstract with
> some of this stuff though ;) I guess I'm wondering if at compile time a
> function for each type (of T) is generated,

That's right.

> and what kind of slowdowns or
> bulk and the sorts ends up in most peoples code.

A compiler/linker should be able to remove multiple copies of generated
functions, ut this is a QOI issue of course.

> I've got all my templates
> working (... now I do anyways...), but I want to understand what was going
> on. I guessing, since this stuff could end up in a dll and the likes, that
> there is only one function created, unless you specify the "template < >
> SomeThing < aSpecialType > (...)". But all I really have is alot of
> guesswork and code that I bruteforced from a verbose compiler 0.o
>

It doesn't make sense to try an put a template in a DLL, since templates
cannot be object code, only instantiations of templates are object code.
Since templates don't get instantiated until they are used there is nothing
to put in a DLL. This is the same reason that template code goes in header
files not in source files.

You can explicitly instantiate a template and that instantiated template
could go in a DLL. But then you are limited to the instantiates you make
ahead of time (when you compile the DLL).

john



Relevant Pages

  • Re: [!! RANT !!] This is a hack at best (C4251)
    ... Micro$oft support for STL and standards in general is absolutely appaling. ... The built DLL exports the symbols, so I am not sure why the compiler issues the warnings. ... The function template is completely ignored and not even exported. ... I hope you can provide a fix as to how to get this to work (i.e. compile ...
    (microsoft.public.dotnet.languages.vc)
  • Re: disable reading of asp pages
    ... Don't put your CodeBehind class code in the Page template, ... compile it into a DLL. ... the Page Template will use the compiled DLL instead. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Visual C++ 6.0 DLL question
    ... This method works fine and dandy for regular classes, but what about template ... I found a template class has to be all in the header ... Now I want to include a few template classes in my DLL. ... I go to compile it and the DLL is generated but not LIB or EXP files ...
    (microsoft.public.vc.language)
  • Re: [!! RANT !!] This is a hack at best (C4251)
    ... The template function won't be generated until it's instantiated. ... really cannot export template functions from a DLL. ... templatevoid foo ... the compile complains as ff: ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Protecting against type mismatch errors
    ... The VBA project in the template that I will be distributing with the DLL is ... Or they might know too much and try to use, say, an Excel ... the macros, with minor/major tweaking will work with Excel. ...
    (microsoft.public.vb.general.discussion)