Where does a template function get instantiated ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 30

Thread: Where does a template function get instantiated ?

Threaded View

  1. #18
    Join Date
    Apr 1999
    Posts
    27,444

    Re: Where does a template function get instantiated ?

    Quote Originally Posted by John E View Post
    Is it considered bad practice (or at least very risky) for a template class to have static data members?
    When you have multi-module projects, it is risky, template class or concrete class, to have static data members. This is the case especially if you rely on the static data being initialized at the point where you're accessing the static data.

    The rules of C++ for when static data members are guaranteed to be initialized get complex (at least to me they are). If you have the entire program in a single module, static initialization becomes easy. It's when you're dealing with multi-module programs where it becomes risky.

    Here is a link to such a scenario:
    http://www.parashift.com/c++-faq/static-init-order.html

    I have also seen static members declared in other modules to not be initialized after main() is called.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; October 21st, 2013 at 02:31 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center