Thread: Templates: VC++ versus C++ standard

  1. #1
    Registered User
    Join Date
    Jul 2005

    Templates: VC++ versus C++ standard

    I'm sorry to bother you guys again Yet I'm still resolutely determined to learn C++ (while weird and illogical at times, it seems a powerful language; plus, C++ programming pays well, for what I know).

    My question is, What if I need to declare a template function in a separate .cpp file, compile it and then link with the main program? I've Googled for it, and several tutorials say that I can't; I have to put the function definition in the .hpp, because "That's the way it works".
    On the other hand, Bjarne Stroustroup says (in "The C++ programming language, 3rd ed.", page 351):
    Note that to be accessible from other compilation units, a template definition must be explicitly declared export (9.2.3). This can be done by adding export to the definition or to a preceding declaration. Otherwise, the definition must be in scope wherever the template is used.
    The problem is, Microsoft VC++ doesn't understand the keyword 'export'. What can I do about it?

    Thank you

  2. #2
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    What can I do about it?
    You won't like this answer. You'll do nothing, if you know what's good for you. The only compiler I know of that implements export is Comeau. But export doesn't quite do what everyone thinks it does so it's a feature ripe with subtle errors. It's better to avoid it until more compilers support it and the daring C++ites get themselves all bloodied up figuring out how to use it safely. Then you can use what they learned without getting the scars yourself.
    Just because I don't care doesn't mean I don't understand.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array initialization & C standard
    By jim mcnamara in forum C Programming
    Replies: 2
    Last Post: 09-12-2008, 03:25 PM
  2. Bug in iterator comparison in C++ standard?
    By steev in forum C++ Programming
    Replies: 14
    Last Post: 07-12-2008, 12:02 AM
  3. Replies: 8
    Last Post: 03-08-2008, 08:50 PM
  4. Using c++ standards
    By subdene in forum C++ Programming
    Replies: 4
    Last Post: 06-06-2002, 09:15 AM
  5. standard language, standard compiler?
    By doubleanti in forum A Brief History of
    Replies: 8
    Last Post: 09-03-2001, 04:21 AM