CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 30

Threaded View

  1. #18
    Join Date
    Apr 1999

    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:

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


    Paul McKenzie
    Last edited by Paul McKenzie; October 21st, 2013 at 01: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

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.